我在项目中使用webpack时遇到了这样的问题:
webpack.config.js使用了两个entry,一个app是源代码,一个vendor是依赖包。output
的文件名使用chunkhash作为后缀,每一次执行npm run build生成的两个js文件,
当app中源代码改变了,再重新build,这时生成的两个js文件chunkhash值都会改变。
这是什么原因呢?webpack.config.js如下:
entry: {
app: "./src/index",
vendor: ["antd",'react','echarts','codemirror','echarts-for-react','react-dnd',
'react-dnd-html5-backend','react-dom','react-fetch','react-redux','react-router',
'superagent','react-router-redux','redux','redux-react-fetch','redux-thunk',
'react-syntax-highlighter','g2','history','isomorphic-fetch','js-cookie',
'lodash','moment','pubsub-js',"react-codemirror"]
}
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle-[name]-[chunkhash].js',
publicPath: '/'
},
<img></img>
看文档https://doc.webpack-china.org/guides/caching 专门讲了你的问题。