【发布时间】:2020-07-20 06:51:41
【问题描述】:
我正在使用 Vue 和 Laravel 构建一个 Web 应用程序。 我在后台使用 Laravel mix 和 Webpack 进行代码拆分和版本控制。
但是,每当我对代码进行更改时,运行 npm run production 并在实时服务器上上传,我经常收到 TypeError: "e[r] is undefined"
我必须在页面正确加载之前手动清除浏览器缓存。 我已经启用了版本控制,因此缓存清除应该是自动化的。
下面是我的 webpack.mix.js 文件
const mix = require('laravel-mix');
const webpack = require('webpack');
mix.webpackConfig({
plugins: [
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
]
})
const CompressionPlugin = require('compression-webpack-plugin');
module.exports = {
plugins: [new CompressionPlugin()],
optimization: {
minimize: true,
namedModules: true,
namedChunks: true,
removeAvailableModules: true,
flagIncludedChunks: true,
occurrenceOrder: false,
usedExports: true,
concatenateModules: true,
sideEffects: false, // <----- in prod defaults to true if left blank
}
};
/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel application. By default, we are compiling the Sass
| file for the application as well as bundling up all the JS files.
|
*/
mix.js('resources/js/main/main.js', 'public/v1.4.0/js')
.sass('resources/sass/app.scss', 'public/css')
.extract(['vue'])
.version();
【问题讨论】:
-
当你再次看到错误时运行
npm run dev尝试检查导致此问题的行 -
开发模式下一切正常。只有当我清除缓存或强制重新加载时,它才能在生产模式下运行
标签: laravel webpack laravel-mix