Given the following two files :
//a.js
export const X = /*#__PURE__*/ "X";
const a = function () {
return "About a!";
};
a.foo = function () {
return "foo";
};
export default a;
and
//main.js
import { X } from "./a";
import { Y } from "./b";
console.log(X, Y);
I have added
"sideEffect": false
topackage.json
optimization.usedExports: true
towebpack.config.js
but running webpack -p
still includes the whole a.js
file in the bundle. Rollup only includes X
from a.js
(demo)
Removing the a.foo
definition "fixes" the issue but is not a solution outside the demo repository.
I have read the tree-shaking documentation page multiple times, read [countless issues about tree shaking on the webpack issue tracker, I still cant figure out the following :
- Why is the
/*#__PURE__*/
marker onX
not being used ? - Is there a way to configure webpack to only include X from
a.js
?
You can also checkout the sandbox repository to see the full webpack configuration and the corresponding next.js/react issue (see pages/index.jsx) which led me to this specific issue.