Vau*_*rin 6 javascript browser-cache webpack vue.js laravel-mix
问题
我的缓存 Vue.js 组件有问题,我无法在我的设备上重现这个问题,但每次客户端更新我们都会让用户抱怨接口损坏,只有清除浏览器缓存才有帮助。
我使用 Laravel + Vue.js 和它的多页应用程序。
战略
app.js 中包含的一个文件中描述的所有组件,它看起来像这样:
Vue.component('task-feed', () => import('./components/task/task-feed'/* webpackChunkName: "/js/components/task-feed" */));
Vue.component('task-item', () => import('./components/task/task-item'/* webpackChunkName: "/js/components/task-item" */));
Run Code Online (Sandbox Code Playgroud)
有 vue.js 异步组件。
然后我像这样配置了 webpack.mix:
let mix = require('laravel-mix');
const webpack = require('webpack');
const ChunkManifestPlugin = require('chunk-manifest-webpack-plugin');
const WebpackChunkHash = require('webpack-chunk-hash');
mix.disableNotifications();
let config = {
watchOptions: {
ignored: /node_modules/
},
resolve: {
alias: {
'vue$': mix.inProduction() ? 'vue/dist/vue.runtime.min.js' : 'vue/dist/vue.runtime.js',
}
},
output: {
chunkFilename: mix.inProduction() ? '[name].[chunkhash].js' : '[name].js',
},
plugins: [
new webpack.HashedModuleIdsPlugin(),
new WebpackChunkHash(),
new ChunkManifestPlugin({
filename: '/js/chunk-manifest.json',
manifestVariable: 'webpackManifest',
inlineManifest: true,
}),
],
};
mix.webpackConfig(config);
Run Code Online (Sandbox Code Playgroud)
我在这里使用 ChunkManifestPlugin,该插件创建 chunk-manifest.json 并将其加载到主布局中,如下所示:
window.webpackManifest = JSON.parse(@json(file_get_contents(public_path('/js/chunk-manifest.json'))));
Run Code Online (Sandbox Code Playgroud)
问题
这里可能有什么问题?任何人都可以建议解决这个问题的方法吗?
小智 6
将webpack.mix.js其更改为:
mix.config.webpackConfig.output = {
chunkFilename: 'scripts/[name].[chunkhash].js',
publicPath: '/',
};
Run Code Online (Sandbox Code Playgroud)
请参阅本文了解更多信息。
| 归档时间: |
|
| 查看次数: |
4631 次 |
| 最近记录: |