-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Treeshaking doesn't take place - lodash #6925
Comments
I know that I can use I cannot use
|
This is expected, since the main lodash package still uses CJS imports/exports. However this should work now with webpack 4 and lodash-es, since it makes use of the new |
Yes, I saw that after looking into the lodash source file.
But the |
@Legends with TS >= 2.7, if you enable import times from 'lodash/times'; and it works. |
@aj-r I have enabled interop, this is not an issue. Treeshaking works if I install `lodash` and do: `import times from 'lodash/times';` The issue I have now, is that treeshaking doesn't take place with Command: page2.ts
webpack.config.ts
|
Hey @Legends, I'm gonna reference webpack-contrib/uglifyjs-webpack-plugin#267 here in case it's related. I wonder if I should submit a separate issue. As far as I can tell, tree-shaking w uglify js plugin just isn't working in webpack 4 at all 😕 |
From the image you posted one can't see if treeshaking is working or not. It only affects the minimized size. All modules are still in the bundle (but smaller). Only the sideEffects optimization removes unused modules, but you disabled this optimization. |
I guess, I missunderstood |
@Legends we talked about it in this other thread (small world :) |
I found the issue, it's coupled to After setting Treeshaking won't work, If Bug?
?? |
I have the same problem, webpack@4.10.2 and lodash-es still not treeshaking, and my webpack.config.js don't have the devtool config. It seems like a bug, anyone successfully used sideEffects treeshaking? thanks. |
@Oscar-ren Are you running in production mode? If yes, can you create a little test repo which reproduces your problem |
thank you, there is my repository: |
Sorry, I run the project on my cloud server, everything is ok, I will find the reason why my macbook doesn't... ReasonI find the reason. {
"presets": [
["env", {
"modules": false
}]
]
} so thanks. |
@Oscar-ren Changing .babelrc file as per your suggestion solved the treeshaking issue for me. {
"presets" : [
[
"env", {
"modules": false
}
],
"react",
"stage-2"
]
} Thanks |
Helped for me to remove sourcemaps and add alias for lodash -> lodash-es! |
Do you want to request a feature or report a bug?
Bug?
What is the current behavior?
I am loading a single export from lodash, but get the complete lodash in output-bundle.js.
If the current behavior is a bug, please provide the steps to reproduce.
page1.ts
Webpack.config.ts
What is the expected behavior?
Treeshaked output.
If this is a feature request, what is motivation or use case for changing the behavior?
Please mention other relevant information such as the browser version, Node.js version, webpack version, and Operating System.
Win10 x64
webpack 4.4.1
node 8.10
The text was updated successfully, but these errors were encountered: