未验证 提交 1fb1b752 编写于 作者: J Joe Haddad 提交者: GitHub

Ensure all modules are identified (#6656)

* Ensure all modules are identified

* Extend a webpack Plugin
Co-Authored-By: NTimer <timer150@gmail.com>
上级 a38c6cb3
......@@ -11,6 +11,7 @@ import { SERVER_DIRECTORY, REACT_LOADABLE_MANIFEST, CLIENT_STATIC_FILES_RUNTIME_
import { NEXT_PROJECT_ROOT, NEXT_PROJECT_ROOT_NODE_MODULES, NEXT_PROJECT_ROOT_DIST_CLIENT, PAGES_DIR_ALIAS, DOT_NEXT_ALIAS } from '../lib/constants'
import {TerserPlugin} from './webpack/plugins/terser-webpack-plugin/src/index'
import { ServerlessPlugin } from './webpack/plugins/serverless-plugin'
import { AllModulesIdentifiedPlugin } from './webpack/plugins/all-modules-identified-plugin'
import { WebpackEntrypoints } from './entries'
type ExcludesFalse = <T>(x: T | false) => x is T
......@@ -282,6 +283,9 @@ export default function getBaseWebpackConfig (dir: string, {dev = false, isServe
return devPlugins
})() : []),
!dev && new webpack.HashedModuleIdsPlugin(),
// This must come after HashedModuleIdsPlugin (it sets any modules that
// were missed by HashedModuleIdsPlugin)
!dev && new AllModulesIdentifiedPlugin(),
!dev && new webpack.IgnorePlugin({
checkResource: (resource: string) => {
return /react-is/.test(resource)
......
import { Compiler, Plugin } from 'webpack'
export class AllModulesIdentifiedPlugin implements Plugin {
apply(compiler: Compiler) {
compiler.hooks.compilation.tap(
'AllModulesIdentifiedPlugin',
compilation => {
compilation.hooks.beforeModuleIds.tap(
'AllModulesIdentifiedPlugin',
modules => {
;(modules as any[]).forEach(module => {
if (module.id != null || !module.identifier) {
return
}
module.id = module.identifier()
})
}
)
}
)
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册