-
-
Notifications
You must be signed in to change notification settings - Fork 179
Tree shaking not working - webpack 4 and uglifyjs-webpack-plugin #267
Comments
Thanks for issue, dup #206 |
@gpspake feel free to ping me, if it is not help |
@evilebottnawi, thanks. I read that thread before submitting and I just re-read it hoping to find a solution but I still don't understand why webpack seems to silently ignore UglifyJsPlugin. My project has a minimal configuration and I am not using React so the code is relatively straight forward for this example. I have tried a lot of the suggestions in that thread but, at the end of the day, treeshaking still isn't working. Can you give me any advice about what's causing this to happen and how I might fix it? |
@gpspake tomorrow i will investigate |
Hey @evilebottnawi, I see you added needs more info tag. Is there any additional info I can provide? |
@gpspake i ping you if something need, in future i think we will use other label aka |
I just want to add one piece of info that I confirmed this morning which is that adding UglifyJsPlugin to my webpack config doesn't have any effect at all. If I comment |
Its happening with me also. Have a simple webpack.config.js and uglify does not get executed irrespective what the environment variable is. |
@shivkoirala can you create minimum reproducible test repo? |
@evilebottnawi below are details let me know if you need anything more Typescript version :- 2.7.2
tsconfig.json
package.json
|
@shivkoirala can you create this as minimum reproducible test repo? |
I'm experiencing what I think is the same issue on this project. Since switching to Webpack 4, production builds are ~400kB larger than Webpack 3 builds with the same codebase. |
Could we please get a minimal reproducable example of uglifyjs-webpack-plugin working with webpack 4? Has anyone actually used it successfully? |
Not sure, perhaps the new way of adding the plugin is using
|
Thanks @Legends. I updated my webpack config. Still no tree-shaking 😢 but at least webpack seems to be honoring my uglify config with that syntax. I'm losing my mind over this. My project is so simple and it seems like treeshaking should be working here based on a lot of the examples I've seen but nothing is working for me.
Yet, somehow, leftpad and even the associated comments are being included in my bundle. |
I would say... probably a bug... |
When |
Thanks @Legends; That helps! If I remove According to the devtool docs, So, I'm still a little confused about sourcemap behavior but I think it's safe to say that treeshaking is working. |
If you are still using UglifyJsPlugin:
But this doesn't help either. I would suggest to open a new issue, if it's not a bug, at least the docs could be updated regarding this.. |
Is this solved? |
@Legends looks no, feel free to docs/fix PR |
@evilebottnawi This can be closed, it's not an issue. |
I have the same issue : tree shaking seems not working for me . part of my webpack.config.js:
Firstly, I am using React framework. Now, I am optimizing the homepage in my app, but I found my index.js import I found this issue and try @gpspake 's idea, but not working for me .And I found @Legends created a new issue and closed it .I don't know why . PS: I using webpack 4.6 to do the test . the size of new file (about PageHeader) is big.But when I upgrade webpack to 4.8.3, the size of new file is bigger than previous one.I am confusing. Updated: I followed the steps in Tree Shaking Documentation:
And also not work. |
Has anyone solved this issue? I'm using "webpack": "^4.5.0", "uglifyjs-webpack-plugin": "^1.2.7", and "react": "^16.3.1". Webpack creates my bundle without removing anycode. |
Running production mode with UglifyJSPlugin enabled will strip the methods. |
My recent discovery was that you also need to use ModuleConcatenationPlugin for the tree shaking to take place. Maybe that will be of any help to anyone - I've created PR to the docs (was accepted). Cheers. |
Has anyone solved this issue? |
I'm having the same problem. No code is removed in bundle generation |
|
I have tried adding UglifyJSPlugin to a webpack 4 project, in accordance with the webpack tree shaking docs, and I'm still seeing dead code and even comments in my bundle which leads me to think that my uglify plugin config isn't being used. I posted this on Stack Overflow a couple of days ago before posting here.
Link to project
The docs state that "in order to take advantage of tree shaking, you must...
Still, the unused/unimported leftpad function and comments are being included in my bundle.
All of the config can be seen here. Based on the results I'm seeing, I suspect that this is related to the uglify settings in my webpack config.
To reproduce:
The text was updated successfully, but these errors were encountered: