all, I'm new to Webpack. Currently, I'm facing a question with webpack tree shaking. In CommonJS, webpack cannot do tree shaking because of the require
syntax. For example, a program can import packages from below ways but tree shaking cannot be worked,
var a;
if(condition){
a = require('module1');
}else{
a = require('module2');
}
Then, tree shaking is based on import
static syntax from ES6 modules, package cannot be imported dynamically.
However, in es7, there is a dynamic way to load modules by lazy loading import (module)
. So, my question is can tree shaking still work if the program contains lazy loading syntax, if webpack can do that, how is this achieved?