Skip to content

Commit

Permalink
Use entry option instead of custom make hook (#14527)
Browse files Browse the repository at this point in the history
Simplifies on-demand-entries a bit.
  • Loading branch information
timneutkens authored Jun 26, 2020
1 parent c6dc34e commit ae542b8
Show file tree
Hide file tree
Showing 15 changed files with 229 additions and 443 deletions.
38 changes: 17 additions & 21 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -694,11 +694,15 @@ export default async function getBaseWebpackConfig(
: {}),
}
},
watchOptions: {
ignored: ['.git/**', 'node_modules/**', '.git/**'],
},
output: {
path: outputPath,
// On the server we don't use the chunkhash
filename: dev || isServer ? '[name].js' : '[name]-[chunkhash].js',
libraryTarget: isServer ? 'commonjs2' : 'var',
library: isServer ? undefined : '_N_E',
libraryTarget: isServer ? 'commonjs2' : 'assign',
hotUpdateChunkFilename: isWebpack5
? 'static/webpack/[id].[fullhash].hot-update.js'
: 'static/webpack/[id].[hash].hot-update.js',
Expand Down Expand Up @@ -894,16 +898,9 @@ export default async function getBaseWebpackConfig(
const {
NextJsRequireCacheHotReloader,
} = require('./webpack/plugins/nextjs-require-cache-hot-reloader')
const {
UnlinkRemovedPagesPlugin,
} = require('./webpack/plugins/unlink-removed-pages-plugin')
const devPlugins = [
new UnlinkRemovedPagesPlugin(),
new NextJsRequireCacheHotReloader(),
]
const devPlugins = [new NextJsRequireCacheHotReloader()]

// Webpack 5 enables HMR automatically in the development mode
if (!isServer && !isWebpack5) {
if (!isServer) {
devPlugins.push(new webpack.HotModuleReplacementPlugin())
}

Expand Down Expand Up @@ -1038,6 +1035,16 @@ export default async function getBaseWebpackConfig(
}
}

// Backwards compat with webpack-dev-middleware options object
if (typeof config.webpackDevMiddleware === 'function') {
const options = config.webpackDevMiddleware({
watchOptions: webpackConfig.watchOptions,
})
if (options.watchOptions) {
webpackConfig.watchOptions = options.watchOptions
}
}

function canMatchCss(rule: webpack.RuleSetCondition | undefined): boolean {
if (!rule) {
return false
Expand Down Expand Up @@ -1262,16 +1269,5 @@ export default async function getBaseWebpackConfig(
webpackConfig.entry = await (webpackConfig.entry as webpack.EntryFunc)()
}

// In webpack 5, the 'var' libraryTarget output requires a name.
// TODO: this should be revisited as 'var' was only used to not have the
// initial variable exposed. In webpack 4, not setting the library option
// would result in the bundle being a self-executing function without the
// variable.
if (isWebpack5 && !isServer) {
webpackConfig.output!.library = webpackConfig.output?.library
? webpackConfig.output.library
: 'INTERNAL_NEXT_APP'
}

return webpackConfig
}
3 changes: 2 additions & 1 deletion packages/next/build/webpack/plugins/build-manifest-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ function generateClientManifest(
}

function isJsFile(file: string): boolean {
return file.endsWith('.js')
// We don't want to include `.hot-update.js` files into the initial page
return !file.endsWith('.hot-update.js') && file.endsWith('.js')
}

// This plugin creates a build-manifest.json for all assets that are being output
Expand Down
36 changes: 0 additions & 36 deletions packages/next/build/webpack/plugins/unlink-removed-pages-plugin.ts

This file was deleted.

20 changes: 0 additions & 20 deletions packages/next/compiled/webpack-dev-middleware/LICENSE

This file was deleted.

1 change: 0 additions & 1 deletion packages/next/compiled/webpack-dev-middleware/index.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/next/compiled/webpack-dev-middleware/package.json

This file was deleted.

2 changes: 0 additions & 2 deletions packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@
"@types/styled-jsx": "2.2.8",
"@types/terser-webpack-plugin": "2.2.0",
"@types/text-table": "0.2.1",
"@types/webpack-dev-middleware": "2.0.3",
"@types/webpack-hot-middleware": "2.16.5",
"@types/webpack-sources": "0.1.5",
"@zeit/ncc": "0.22.0",
Expand Down Expand Up @@ -213,7 +212,6 @@
"typescript": "3.8.3",
"unfetch": "4.1.0",
"unistore": "3.4.1",
"webpack-dev-middleware": "3.7.0",
"webpack-hot-middleware": "2.25.0"
},
"engines": {
Expand Down
Loading

0 comments on commit ae542b8

Please sign in to comment.