我有一个 React/Node + SSR 应用程序,我正在尝试创建一个生产构建,我已经设法做到了,但问题是我在构建中的文件太大了。我使用最新版本的 react + webpack 4。这是我的 webpack 配置:
客户端配置文件
const path = require('path');
const common = require('./webpack.common-config');
const clientConfig = {
...common,
mode: 'production',
name: 'client',
target: 'web',
devtool: false,
entry: {
client: [
'@babel/polyfill',
'./src/client.js'
],
},
output: {
path: path.resolve(__dirname, 'build'),
filename: '[name].js',
},
optimization: {
splitChunks: {
cacheGroups: {
vendor: {
chunks: 'all',
name: 'vendor',
test: module => /node_modules/.test(module.resource),
enforce: true
},
common: {
chunks: 'all',
name: 'client'
}
},
},
},
node: { …Run Code Online (Sandbox Code Playgroud)