I have a specific question below, but I think the more general question is, how can I control what webpack adds to my build automatically (especially without depending on external modules)?
I have a simple 10-line js example I’m trying to use with webpack. When I run locally with webpack-dev-server, I see that bundle.js
is >300KB. I assume this is because node_modules
is being included, correct?
The file size of dist/bundle.js is ~2KB, so this is apparently being done at runtime.
I’ve added babel-loader and the necessary rules as specified on the package’s repo README to my webpack config. I don’t receive any errors when running locally, so I assume that the configuration is now correct.
However, my bundle.js is still showing 300KB+ in dev tools. How can I get rid of this stuff? This is simply a short example with plain JS inserting a single DOM element, so I (obviously) don’t need all the extra stuff.
None of the existing SO posts or blog articles I’ve been able to locate have been helpful (they all use some variation of exclude
, and I’ve tried them all, and have seen config errors in cases where they weren’t specified correctly, so that’s why I believe it’s specified correctly now).
(Posting here because webpack questions are no longer answered on SO, which leaves no other resources AFAIK.)
Use
webpack --json > analysis.json
and run the JSON file through https://webpack.github.io/analyse/ to see which modules are being included.Webpack certainly doesn’t bundle everything from
node_modules
by default.It looks like you just deleted/ignored our lovely crafted issue template. It was there for good reasons. Please help us solving your issue by answering the questions asked in this template. I’m closing this. Please open a new issue with filled issue template. Also make sure your issue is not a question. Questions should be posted on Stack Overflow.
The very popular module webpack-node-externals appears to address this issue:
https://www.npmjs.com/package/webpack-node-externals
@hutch120
It doesn’t work for me.
Webpack.config.js
package.json