Webpack 2 块名称包含未定义
Webpack 2 chunk name contains undefined
我正在尝试升级到 Webpack 2。我成功地将代码拆分与按需加载(使用 require.ensure)与 Webpack 1 结合使用。但是,对于 webpack 2,块的文件名包含一个 "undefined",这导致它变为 404.
webpack.config.js
{
entry: {
'main': 'index.ts',
'vendor': 'vendor.ts'
},
output: {
filename: '[name].[hash].bundle.js',
chunkFilename: '[hash].js',
path: path.resolve(__dirname, '../dist')
},
devServer: {
proxy: {
//proxy info
}
},
resolve: {
modules: [
helper.root('src'),
'node_modules'
],
extensions: ['.ts', '.js', '.json'],
},
cache: false,
devtool: 'cheap-source-map',
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: function (module) {
return module.context && module.context.indexOf('node_modules') !== -1;
}
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'manifest'
}),
new ExtractTextPlugin({
filename:'[name]-[hash].css',
allChunks: true
}),
new HtmlWebpackPlugin({
template: './src/index.html',
inject: true
}),
new ngAnnotatePlugin({
add: true
}),
new OptimizeCssAssetsPlugin({
assetNameRegExp: /\.optimize\.css$/g,
cssProcessor: require('cssnano'),
cssProcessorOptions: { discardComments: { removeAll: true } },
canPrint: true
}),
new webpack.LoaderOptionsPlugin(require('../tslint.json')),
new webpack.LoaderOptionsPlugin({
configFile: './.htmlhintrc'
}),
new webpack.LoaderOptionsPlugin({
configFile: './.sass-lint.yml'
}),
new DashboardPlugin(),
new webpack.ContextReplacementPlugin(/moment[\\/]locale$/, /^\.\/(de|en|fr|ko|ja|zh-cn)$/)
],
module: {
rules: loaders
},
}
我已经尝试过 chunkFilename 的不同变体(在许多组合中使用 [name]、[id]、[chunkhash])。 None 他们的工作。我该如何解决这个问题?
找到问题了。我将 __webpack_public_path
设置为一个未定义的变量。
我正在尝试升级到 Webpack 2。我成功地将代码拆分与按需加载(使用 require.ensure)与 Webpack 1 结合使用。但是,对于 webpack 2,块的文件名包含一个 "undefined",这导致它变为 404.
webpack.config.js
{
entry: {
'main': 'index.ts',
'vendor': 'vendor.ts'
},
output: {
filename: '[name].[hash].bundle.js',
chunkFilename: '[hash].js',
path: path.resolve(__dirname, '../dist')
},
devServer: {
proxy: {
//proxy info
}
},
resolve: {
modules: [
helper.root('src'),
'node_modules'
],
extensions: ['.ts', '.js', '.json'],
},
cache: false,
devtool: 'cheap-source-map',
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: function (module) {
return module.context && module.context.indexOf('node_modules') !== -1;
}
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'manifest'
}),
new ExtractTextPlugin({
filename:'[name]-[hash].css',
allChunks: true
}),
new HtmlWebpackPlugin({
template: './src/index.html',
inject: true
}),
new ngAnnotatePlugin({
add: true
}),
new OptimizeCssAssetsPlugin({
assetNameRegExp: /\.optimize\.css$/g,
cssProcessor: require('cssnano'),
cssProcessorOptions: { discardComments: { removeAll: true } },
canPrint: true
}),
new webpack.LoaderOptionsPlugin(require('../tslint.json')),
new webpack.LoaderOptionsPlugin({
configFile: './.htmlhintrc'
}),
new webpack.LoaderOptionsPlugin({
configFile: './.sass-lint.yml'
}),
new DashboardPlugin(),
new webpack.ContextReplacementPlugin(/moment[\\/]locale$/, /^\.\/(de|en|fr|ko|ja|zh-cn)$/)
],
module: {
rules: loaders
},
}
我已经尝试过 chunkFilename 的不同变体(在许多组合中使用 [name]、[id]、[chunkhash])。 None 他们的工作。我该如何解决这个问题?
找到问题了。我将 __webpack_public_path
设置为一个未定义的变量。