使用HtmlWebpackPlugin时未定义webpackManifest
我试图使用HtmlWebpackPlugin()生成index.html,但是当我尝试使用以下配置(用于缓存)时,我发现webpackManifest没有插入到页面中,并且出现了一个“未定义”错误。这是我的配置文件:使用HtmlWebpackPlugin时未定义webpackManifest,webpack,webpack-2,Webpack,Webpack 2,我试图使用HtmlWebpackPlugin()生成index.html,但是当我尝试使用以下配置(用于缓存)时,我发现webpackManifest没有插入到页面中,并且出现了一个“未定义”错误。这是我的配置文件: module.exports = function(env) { return { entry: { main: './app/index.js', vendor: ['moment','lodash','jq
module.exports = function(env) {
return {
entry: {
main: './app/index.js',
vendor: ['moment','lodash','jquery']
},
output: {
filename: '[name].[chunkhash].js',
path: path.resolve(__dirname, 'dist'),
publicPath : './'
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: ["vendor", "manifest"]
}),
new webpack.HashedModuleIdsPlugin(),
new WebpackChunkHash(),
new ChunkManifestPlugin({
filename: "chunk-manifest.json",
manifestVariable: "webpackManifest"
}),
new HtmlWebpackPlugin({
chunksSortMode: 'dependency',
hash : true
}),
new ScriptExtHtmlWebpackPlugin()
]
}
};
错误是:
Uncaught TypeError: Cannot read property '0' of undefined
script.src = __webpack_require__.p + window["webpackManifest"][chunkId];
我试过了,上面的配置工作正常,试试这个
const HtmlWebpackPlugin=require('html-webpack-plugin');
var WebpackChunkHash=require('webpack-chunk-hash');
const ChunkManifestPlugin=require('chunk-manifest-webpack-plugin');
const ScriptExtHtmlWebpackPlugin=require('script-ext-html-webpack-plugin');
const path=require('path');
const webpack=require('webpack');
var webpackConfig=函数(env){
返回{
条目:{
main:“./src/index.js”,
供应商:['moment'、'lodash'、'jquery']
},
输出:{
path:path.resolve(uu dirname,'dist'),
文件名:'[name].[chunkhash].js',,
公共路径:'./'
},
插件:[
新的HtmlWebpackPlugin({
ChunksortMode:“依赖项”,
哈希:对
}),
新建webpack.optimize.commonChunkPlugin({
名称:[“供应商”、“清单”]
}),
新建webpack.HashedModuleIdsPlugin(),
新建WebPackageChunkHash(),
新插件({
文件名:“chunk manifest.json”,
manifestVariable:“WebPackageManifest”,
inlineManifest:false
}),
新ScriptExtHtmlWebpackPlugin()
]
}
};
module.exports=webpackConfig代码>我无法重现问题
,看起来您的配置不正确fine@goonieiam“你解决过这个问题吗?”古尼亚姆:有什么需要帮忙的吗