-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
[WIP] Split vendor bundle #2310
Conversation
74c5b03
to
fa83243
Compare
Just a general wondering: Is it a good idea to add this vendor ability without controlling the parameters for the CommonsChunkPlugin? I haven't used it in a while but I remember it having issues with bundling the entire libraries specified in vendor and not just the required bits. Is that not a thing anymore? |
@SR-H you can control what goes into vendor bundle. // vendor.js
import React from 'react';
import 'lodash/func1';
import 'lodash/func2';
import 'lodash/func3';
import 'lodash/func4'; |
cc #2328 |
in context of the acticle linked in facebook#2328
465e22a
to
9345cfa
Compare
} | ||
return chunk.modules | ||
.map(m => path.relative(m.context, m.request)) | ||
.join('_'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the only thing to keep in mind here is, that this could potentially become a length string, so it might make sense to cut the string at a certain point or use a hash digest or something similar.
Would probably need real life testing to see if it really becomes an issue.
the most brutal way would be to digest
the paths, but that would mean one looses the ability to see what actually got required. maybe a healthy mix of both?
new webpack.NamedChunksPlugin(chunk => {
if (chunk.name) {
return chunk.name;
}
// const crypto = require('crypto');
const pathDigest = crypto.createHash('md5');
return chunk.modules
.map(m => path.relative(m.context, m.request))
.reduce((d, m )=> d.update(m), pathDigest)
.digest('base64');
// If the vendor file exists, add an entry point for vendor, | ||
// and a seperate entry for polyfills and app index file, | ||
// otherwise keep only polyfills and app index. | ||
const appEntryFiles = [require.resolve('./polyfills'), paths.appIndexJs]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This way vendor bundle does not get the polyfills. Polyfills should the first thing that run from our bundles, else we could get issue similar to this facebook/react#8379 (comment) for promises and fetch. I think we need another check here / move this to a resolver function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@viankakrisna yup makes sense. external libs that depends on promise might get this issue. Plus polyfills are vendor libs.
can't we simply do
const entryFiles = checkIfVendorFileExists
? {
vendor: [require.resolve('./polyfills'), paths.appVendorJs],
main: paths.appIndexJs,
}
: [require.resolve('./polyfills'), paths.appIndexJs];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking about something like this https://github.com/viankakrisna/create-react-app/blob/cb34a1baf21497ad1de7eb314d9ba97a89f1c0be/packages/react-dev-utils/webpackAutoDllCompiler.js#L82-L111 I feel that ejected users should not be bothered by an optional feature checks when they ejected.
Hi @shrynx, how is going it to work? I add all the vendors in my project (for example, lodash, mobx, etc.) in vendor.js and I would use in other file without import? I was using that in my custom projects, but I want to migrate to CRA.
Where isVendor is like this:
Thanks!! |
@@ -250,6 +265,41 @@ module.exports = { | |||
], | |||
}, | |||
plugins: [ | |||
// configuration for vendor splitting and long term caching | |||
// more info: https://medium.com/webpack/predictable-long-term-caching-with-webpack-d3eee1d3fa31 | |||
new webpack.NamedModulesPlugin(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just in case - webpack docs recommend adding also HashedModuleIdsPlugin
for prod build. https://webpack.js.org/guides/caching/#deterministic-hashes
} | ||
: { names: [] } | ||
), | ||
new NameAllModulesPlugin(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is an issue with the plugin that could hurt hashing. didn't have time to elaborate approach though :( timse/name-all-modules-plugin#1
hi all! I was just wondering if there were updates re this PR? thanks! cc @shrynx |
Hello, guys, I wonder if this PR is going to get merged soon |
Hi, any news? :) Thanks! |
Sorry for the long silence. |
This is superseded by #3878. |
PR for #2206
steps to create vendor bundle file
vendor.js
insrc
folder.