Output .js bundle contains everything from node_modules, even not imported
See original GitHub issueDescription
I have this brunch config (listed below), where I’m building 2 output bundles, app.js and admin.js.
app.js is almost empty and does import "phoenix_html"
, while admin.js does import "react"
etc.
Expected behavior
I would expect to have very tiny app.js file as I’m not importing react or anything big there.
Actual behavior
Both files are about 1.3 MB in size (or 350 KB in production build). Both include everything that’s installed in node_modules.
I browsed through existing and closed issues, and people keep saying “only what’s required” gets concatenated. But this is not true. Is “requiring” different from import "...."
when using babel?
Environment
- Brunch: 2.10.12
- Node.js: 6.12
- NPM: 3.10.10
package.json
contents
{
"repository": {},
"license": "MIT",
"scripts": {
"deploy": "brunch build --production",
"watch": "brunch watch --stdin"
},
"dependencies": {
"bootstrap": "^4.0.0-beta",
"jquery": "^3.2.1",
"phoenix": "file:../deps/phoenix",
"phoenix_html": "file:../deps/phoenix_html",
"popper.js": "^1.12.6",
"react": "^16.1.1",
"react-dom": "^16.1.1",
"react-phoenix": "file:../deps/react_phoenix"
},
"devDependencies": {
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"babel-brunch": "6.1.1",
"brunch": "2.10.12",
"clean-css-brunch": "2.10.0",
"sass-brunch": "^2.10.4",
"uglify-js-brunch": "2.1.1"
}
}
brunch config contents
joinTo: {
"js/app.js": ["js/app.js", /^node_modules/],
"js/admin.js": ["js/admin.js",
/^js\/admin\//,
/^js\/components\//,
/^node_modules/],
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Webpack does not import bundles from node_modules (js only)
This problem is not specific only to a specific library but genreally to all libraries. Importing css resources from libraries works fine in ......
Read more >Webpack: How to don't bundle node_modules, but use them ...
It will create a file server.js which only contains my server code. Then creates a server.bundle.js which is not used.
Read more >Webpack is bundling all of the files in node_modules?
So it it normal for bundle.js to be a 7000 line file even though I've only imported React and ReactDOM ?
Read more >How webpack decides what to bundle - Jakob Lind
Webpack builds a dependency graph used internally. Next step for webpack is to check for everything that is imported from those three files....
Read more >A Guide to Managing Webpack Dependencies - Toptal
A Guide to Managing Webpack Dependencies ... The Webpack module bundler processes JavaScript code and all static assets, such as stylesheets, images, and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Having a similar issue that Brunch includes all of the React’s development code (~700Kb) in production build.
The option is to include react into app/lib or something like this. Should work until we figure out how to adjust this.