gpt4 book ai didi

Webpack 生产构建 - TypeError e[t] 未定义

转载 作者:行者123 更新时间:2023-12-02 07:53:26 26 4
gpt4 key购买 nike

所以我让应用程序在本地正常工作,构建也正常工作,但是当我在生产中访问我的主页(唯一有错误的路线)时,我收到此消息。

enter image description here

enter image description here

我不知道这意味着什么,这是我的 webpack 配置文件。

webpack.base.config.js

const path = require('path')
const webpack = require('webpack')
const vueConfig = require('./vue-loader.config')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
const CompressionPlugin = require('compression-webpack-plugin');


const isProd = process.env.NODE_ENV === 'production'

module.exports = {
devtool: isProd
? false
: '#cheap-module-source-map',
output: {
path: path.resolve(__dirname, '../dist'),
publicPath: isProd ? 'https://d267jrn1ysxlb3.cloudfront.net/dist/' : '/dist/',
filename: '[name].[chunkhash].js'
},
resolve: {
alias: {
'public': path.resolve(__dirname, '../public'),
'@': path.resolve('__dirname', '../')
}
},
module: {
noParse: /es6-promise\.js$/, // avoid webpack shimming process
rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
options: vueConfig
},
{
test: /\.js$/,
loader: 'babel-loader',
// exclude: /node_modules/
},
{
test: /\.(png|gif|jpg|jpeg)$/,
loader: 'url-loader',
options: {
limit: 8192,
name: '[path][name].[ext]?[hash]',
publicPath: isProd ? 'https://d267jrn1ysxlb3.cloudfront.net/' : '/'
}
},
{
test: /\.(woff|woff2|eot|ttf|svg)$/,
loader: 'url-loader',
options: {
name: '[name].[ext]?[hash]',
publicPath: isProd ? 'https://d267jrn1ysxlb3.cloudfront.net/assets/fonts/' : '/assets/fonts/'
}
},
{
test: /\.css$/,
use: isProd
? ExtractTextPlugin.extract({
use: {
loader: 'css-loader',
options: {
minimize: true
}
},
fallback: 'vue-style-loader',
})
: ['vue-style-loader', 'css-loader']
}
]
},
performance: {
maxEntrypointSize: 300000,
hints: isProd ? 'warning' : false
},
plugins: isProd
? [
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
drop_console: true
},
minify: true
}),
new ExtractTextPlugin({
filename: 'common.[chunkhash].css'
}),
new CompressionPlugin({
include: /\/dist/,
algorithm: "gzip",
test: /\.js$|\.css$|\.html$/,
threshold: 10240,
minRatio: 0.8
})
]
: [
new FriendlyErrorsPlugin()
]
}

webpack.client.config.js

const glob = require('glob')
const webpack = require('webpack')
const merge = require('webpack-merge')
const base = require('./webpack.base.config')
const SWPrecachePlugin = require('sw-precache-webpack-plugin')
const VueSSRClientPlugin = require('vue-server-renderer/client-plugin')

const config = merge(base, {
entry: {
app: './src/entry-client.js'
},
resolve: {
alias: {
'create-api': './create-api-client.js'
}
},
plugins: [
// strip dev-only code in Vue source
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'),
'process.env.VUE_ENV': '"client"'
}),
// extract vendor chunks for better caching
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: function (module) {
// a module is extracted into the vendor chunk if...
return (
// it's inside node_modules
/node_modules/.test(module.context) &&
// and not a CSS file (due to extract-text-webpack-plugin limitation)
!/\.css$/.test(module.request)
)
}
}),
// extract webpack runtime & manifest to avoid vendor chunk hash changing
// on every build.
new webpack.optimize.CommonsChunkPlugin({
name: 'manifest'
}),
new VueSSRClientPlugin()
]
})

if (process.env.NODE_ENV === 'production') {
config.plugins.push(
// auto generate service worker
new SWPrecachePlugin({
cacheId: 'vue-hn',
filename: 'service-worker.js',
minify: true,
dontCacheBustUrlsMatching: /./,
staticFileGlobsIgnorePatterns: [/\.map$/, /\.json$/],
runtimeCaching: [
{
urlPattern: '/',
handler: 'networkFirst'
},
{
urlPattern: /\/(top|new|show|ask|jobs)/,
handler: 'networkFirst'
},
{
urlPattern: '/item/:id',
handler: 'networkFirst'
},
{
urlPattern: '/user/:id',
handler: 'networkFirst'
}
]
})
)
}

module.exports = config

有人知道从哪里开始吗?

您可以在 v2.propertista.com 上看到此应用程序实时崩溃。)

最佳答案

我有同样的问题,但在我的 React 应用程序上:

  • 当开发 webpack 捆绑时,一切都运行良好。我的控制台日志中没有任何错误,并且从一页到另一页都很顺利
  • 切换到同样“缩小”的生产版本时,我注意到有一个页面无法正确加载(屏幕一片空白)
  • 在控制台日志中,我看到 e[t] is undefined 就像您所做的那样
  • 除此之外,在转到该页面之前刷新并加载另一个页面可以使其再次正常工作

我所做的就是寻找有问题的组件。几个小时后,我发现我从 node_modules 导入的组件是问题所在。这很有意义,因为其他页面(索引页面除外)正在使用它 - 我想这就是为什么在解决该问题之前访问任何页面(索引页面除外)。

为了解决这个问题,我必须更改 webpack.config.js 中的一件事。

我有以下几行:

optimization: {
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/](react|react-dom|redux)[\\/]/,
name: 'vendor',
chunks: 'all',
},
},
},
},

在测试中添加我的第三方解决了问题。例如,如果出现问题的第三方组件来自 react-intl,我会将 test RegExp 更改为以下内容:

test: /[\\/]node_modules[\\/](react|react-dom|redux|react-intl)[\\/]/,

关于Webpack 生产构建 - TypeError e[t] 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48427513/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com