Skip to content
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

Move all NPM modules into a single chunk in dev mode. #1505

Merged
merged 1 commit into from
Mar 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions server/build/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,26 @@ export default async function createCompiler (dir, { dev = false, quiet = false,
name: 'commons',
filename: 'commons.js',
minChunks (module, count) {
// In the dev we use on-deman-entries.
// So, it makes no sense to use commonChunks with that.
if (dev) return false
// In the dev we use on-demand-entries.
// So, it makes no sense to use commonChunks based on the minChunks count.
// Instead, we move all the code in node_modules into this chunk.
// With that, we could gain better performance for page-rebuild process.
if (dev) {
return module.context && module.context.indexOf('node_modules') >= 0
}

// NOTE: it depends on the fact that the entry funtion is always called
// before applying CommonsChunkPlugin
return count >= minChunks
}
}),
// This chunk contains all the webpack related code. So, all the changes
// related to that happens to this chunk.
// It won't touch commons.js and that gives us much better re-build perf.
new webpack.optimize.CommonsChunkPlugin({
name: 'manifest',
filename: 'manifest.js'
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(dev ? 'development' : 'production')
}),
Expand All @@ -121,7 +132,7 @@ export default async function createCompiler (dir, { dev = false, quiet = false,
} else {
plugins.push(
new CombineAssetsPlugin({
input: ['commons.js', 'main.js'],
input: ['manifest.js', 'commons.js', 'main.js'],
output: 'app.js'
}),
new webpack.optimize.UglifyJsPlugin({
Expand Down
1 change: 1 addition & 0 deletions server/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export class NextScript extends Component {
if (dev) {
return (
<div>
{ this.getChunkScript('manifest.js') }
{ this.getChunkScript('commons.js') }
{ this.getChunkScript('main.js') }
</div>
Expand Down
6 changes: 6 additions & 0 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ export default class Server {
await this.serveStatic(req, res, p)
},

'/_next/:hash/manifest.js': async (req, res, params) => {
this.handleBuildHash('manifest.js', params.hash, res)
const p = join(this.dir, '.next/manifest.js')
await this.serveStatic(req, res, p)
},

'/_next/:hash/main.js': async (req, res, params) => {
this.handleBuildHash('main.js', params.hash, res)
const p = join(this.dir, '.next/main.js')
Expand Down