feat(es/bundler): Add an option to disable tree-shaking (#3102)

This commit is contained in:
Alex Alikiotis 2021-12-22 19:53:02 +02:00 committed by GitHub
parent f4cc323e08
commit d98a59339a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 6 deletions

View File

@ -86,6 +86,7 @@ fn do_test(_entry: &Path, entries: HashMap<String, FileName>, inline: bool, mini
external_modules: Default::default(),
disable_fixer: minify,
disable_hygiene: minify,
disable_dce: false,
module: Default::default(),
},
Box::new(Hook),

View File

@ -36,6 +36,9 @@ pub struct Config {
pub disable_fixer: bool,
/// Disable tree-shaking optimization.
pub disable_dce: bool,
/// List of modules which should be preserved.
pub external_modules: Vec<JsWord>,

View File

@ -18,12 +18,12 @@ where
if !self.config.disable_inliner {
node = node.fold_with(&mut constant_propagation())
}
node = node.fold_with(&mut Repeat::new(dce::dce(dce::Config {
// TODO(kdy1): Apply mark to wrapped esms and use it at here.
module_mark: None,
})));
if !self.config.disable_dce {
node = node.fold_with(&mut Repeat::new(dce::dce(dce::Config {
// TODO(kdy1): Apply mark to wrapped esms and use it at here.
module_mark: None,
})));
}
node
})
}

View File

@ -134,6 +134,7 @@ impl TestBuilder {
disable_inliner: true,
disable_hygiene: false,
disable_fixer: false,
disable_dce: false,
external_modules: vec![],
module: Default::default(),
},