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
Handle CommonsChunkPlugin Assets (updated) #84
base: master
Are you sure you want to change the base?
Conversation
… commonschunkplugin
I'm not sure why the $ node --version
v7.7.3
$ npm --version
4.1.2 |
Anything I can do to help here? Would love to be able to split my vendors out and I'm running into the |
@cpsubrian could you check to see why the above test is failing? Other than that, just waiting for the pull request to be accepted. You can use my fork in the meantime. It's working great for me. |
@HorizonXP i'm getting this error ERROR in TypeError: Cannot read property 'call' of undefined |
@HorizonXP i'm getting this error
|
This is what worked for me, no PR or modifications needed to static-site-generator: // Webpack root config
{
entry: {
webApp: './index',
prerenderedApp: './static',
}
...
} // Webpack plugins
const plugins = [
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
chunks: ['vendor', 'webApp'],
minChunks: (module) => {
return module.context && module.context.includes('node_modules');
},
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'manifest',
chunks: ['vendor', 'webApp'],
minChunks: Infinity,
}),
new StaticSiteGeneratorPlugin({
entry: 'prerenderedApp',
paths: [
'/',
'/about',
'/faq',
'/terms',
'/login',
'/privacy',
],
locals: {
fs, // Pass in file system to load a template in static.js
clientPath: config.paths.client(),
contentSecurityPolicy,
},
globals: {
window: {
navigator: {},
matchMedia: () => ({}),
addEventListener: () => {
},
analytics: {
page: () => {
},
},
},
},
}),
]; This configuration lets me build chunked Thus, both static and dynamic apps are generated in one compilation. |
@heisian Thanks for the example! Are you still using static-site-generator-webpack-plugin, and if so any more learnings? We're trying to set ours up this way with Webpack 4, have been running into some issues. Right now we're trying two webpack configs and then hacking after bundles are generated. Interesting idea to stub |
Yes, I don't think the build config has changed much since. |
I haven't tried Webpack 4 yet.. not sure what changes would be needed for the config.. was just getting used to Webpack 3... |
Building on @stephen-haddix 's work, I've rebased his branch against
master
, bringing it up to date. I also updated his test to use the new configuration format, but I did run it using the legacy arguments format, and it worked the same.The biggest change here is the removal of hard-coded chunk names. From https://webpack.js.org/guides/caching/#deterministic-hashes:
(Emphasis added)
Knowing this, we can now handle an arbitrary number of chunks, because we know the
webpackJsonP
function is loaded into the last chunk. Just like in the browser, this last chunk needs to be executed first, so that it can load the necessary chunks and functions for the subsequent chunks to execute properly.Happy to explain it in more detail if required. Let me know if there are any updates you'd like made.