/sideEffects

show the webpack sideEffects config effect

Primary LanguageJavaScript

sideEffects Demo

run

npm run build

entry

src/sideEffects.js

reference

  • src/module/big-module there is no sideEffects config
  • src/module/big-module-with-flag this have sideEffects config
  • lodash-es@4.17.10

env

  • node v8.5.0
  • npm v6.0.0
  • webpack @4.10.2

build result

image

reason

babel transform the module to commonjs, webpack can't treeshaking the commonjs module.

we should config below, let webpack deal with the row code, since the webpack@2, webpack can deal with es6 import and export default syntax.

{
  "presets": [
    ["env", {
      "modules": false
    }]
  ]
}