修改vue项目中 vue.config.js 文件
chainWebpack: config => {
// 添加以下配置
//[contenthash] 是 Webpack 构建时自动生成的,无需手动获取。只需在配置中正确使用它即可实现基于内容的缓存策略。
config.output.filename('js/[name].js?[contenthash]').end();
config.output.chunkFilename('js/[name].js?[contenthash]').end();
}
执行npm run test 打包后
dist-test 打包文件 index.html 入口文件中引入的会变为:
<script src=/vendor/vendor.dll.js> </script>
<script src=/js/chunk-vendors.js?883482877869a902b5fa> </script>
<script src=/js/index.js?42cb4047d1807db226d1> </script>
成功!