Webpack3 带有一个ModuleConcatenation
插件,当与--display-optimization-bailout
标志一起使用时,它会给你提供救助的理由。
救助消息并不那么容易理解,而且很难理解为什么它们会发生在特定模块上。
这是我webpack
的项目非常简化版本的命令输出:
> webpack --bail --display-optimization-bailout
Hash: 4a9a55dc2883e82a017e
Version: webpack 3.4.1
Child client:
Hash: 4a9a55dc2883e82a017e
Time: 594ms
Asset Size Chunks Chunk Names
a.d3ade61d21d5cb8dd426.bundle.js 712 bytes 0 [emitted] a
a.d3ade61d21d5cb8dd426.bundle.js.map 6.57 kB 0 [emitted] a
manifest.json 102 bytes [emitted]
index.html 299 kB [emitted] [big]
[0] multi ./src/client/bootstrap/ErrorTrap.js 28 bytes {0} [built]
ModuleConcatenation bailout: Module is not an ECMAScript module
[1] ./src/client/bootstrap/ErrorTrap.js 199 bytes {0} [built]
ModuleConcatenation bailout: Module is not an ECMAScript module
./src/client/bootstrap/ErrorTrap.js
我尽可能地简化了内容,但我仍然得到ModuleConcatenation bailout: Module is not an ECMAScript module
. 以下是它的内容:
class ErrorTrap {
}
export default ErrorTrap;
我研究了这个救助消息,它发生的原因之一是模块没有导入或导出,如https://github.com/webpack/webpack/blob/93ac8e9c3699bf704068eaccaceec57b3dd45a14/lib/dependencies/ HarmonyDetectionParserPlugin.js#L12-L14,但我不知道为什么不将此模块视为ECMAScript
模块。
.babelrc
{
"presets": [
"es2015"
]
}
webpack.config.js表示:
{ target: 'web',
devtool: 'source-map',
entry: { a: [ './src/client/bootstrap/ErrorTrap.js' ] },
output:
{ path: '/project/build/client/assets',
filename: '[name].[chunkhash].bundle.js',
chunkFilename: '[name].[chunkhash].chunk.js',
publicPath: '/assets/' },
module: { rules: [ [Object], [Object], [Object], [Object], [Object] ] },
resolve: { alias: { 'lodash.defaults': 'lodash' } },
plugins:
[ ModuleConcatenationPlugin { options: {} },
CommonsChunkPlugin {
chunkNames: [Object],
filenameTemplate: undefined,
minChunks: Infinity,
selectedChunks: undefined,
children: undefined,
async: undefined,
minSize: undefined,
ident: '/project/node_modules/webpack/lib/optimize/CommonsChunkPlugin.js0' },
ManifestPlugin { opts: [Object] },
ChunkManifestPlugin {
manifestFilename: 'chunk-manifest.json',
manifestVariable: 'webpackManifest',
inlineManifest: false },
OccurrenceOrderPlugin { preferEntry: undefined },
DefinePlugin { definitions: [Object] },
VisualizerPlugin { opts: [Object] },
ExtractTextPlugin { filename: '[name].[contenthash].css', id: 1, options: {} },
UglifyJsPlugin { options: [Object] },
LoaderOptionsPlugin { options: [Object] } ],
name: 'client' }