mirror of
https://github.com/didi/KnowStreaming.git
synced 2025-12-24 11:52:08 +08:00
feat: 前端打包增加分包策略
This commit is contained in:
@@ -86,12 +86,12 @@ class CoverHtmlWebpackPlugin {
|
|||||||
|
|
||||||
assetJson.reverse().forEach((item) => {
|
assetJson.reverse().forEach((item) => {
|
||||||
if (/\.js$/.test(item)) {
|
if (/\.js$/.test(item)) {
|
||||||
// if (item.includes('vendor~')) {
|
if (item.includes('vendor~')) {
|
||||||
// vendors += `<script async src="${item}"></script>`;
|
vendors += `<script async src="${item}"></script>`;
|
||||||
// } else {
|
} else {
|
||||||
// TODO: entry 只有一个
|
// TODO: entry 只有一个
|
||||||
portalMap['@portal/layout'] = item;
|
portalMap['@portal/layout'] = item;
|
||||||
// }
|
}
|
||||||
} else if (/\.css$/.test(item)) {
|
} else if (/\.css$/.test(item)) {
|
||||||
links += `<link href="${item}" rel="stylesheet">`;
|
links += `<link href="${item}" rel="stylesheet">`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ const TerserJSPlugin = require('terser-webpack-plugin');
|
|||||||
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
|
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
|
||||||
const theme = require('./theme');
|
const theme = require('./theme');
|
||||||
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
|
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
|
||||||
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
|
|
||||||
|
|
||||||
const isProd = process.env.NODE_ENV === 'production';
|
const isProd = process.env.NODE_ENV === 'production';
|
||||||
const babelOptions = {
|
const babelOptions = {
|
||||||
@@ -43,7 +42,6 @@ const babelOptions = {
|
|||||||
module.exports = () => {
|
module.exports = () => {
|
||||||
const cssFileName = isProd ? '[name]-[chunkhash].css' : '[name].css';
|
const cssFileName = isProd ? '[name]-[chunkhash].css' : '[name].css';
|
||||||
const plugins = [
|
const plugins = [
|
||||||
// !isProd && new HardSourceWebpackPlugin(),
|
|
||||||
new CoverHtmlWebpackPlugin(),
|
new CoverHtmlWebpackPlugin(),
|
||||||
new ProgressBarPlugin(),
|
new ProgressBarPlugin(),
|
||||||
new CaseSensitivePathsPlugin(),
|
new CaseSensitivePathsPlugin(),
|
||||||
@@ -150,23 +148,21 @@ module.exports = () => {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
optimization: Object.assign(
|
optimization: Object.assign(
|
||||||
// {
|
|
||||||
// splitChunks: {
|
|
||||||
// cacheGroups: {
|
|
||||||
// vendor: {
|
|
||||||
// test: /[\\/]node_modules[\\/]/,
|
|
||||||
// chunks: 'all',
|
|
||||||
// name: 'vendor',
|
|
||||||
// priority: 10,
|
|
||||||
// enforce: true,
|
|
||||||
// minChunks: 1,
|
|
||||||
// maxSize: 3500000,
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
isProd
|
isProd
|
||||||
? {
|
? {
|
||||||
|
splitChunks: {
|
||||||
|
cacheGroups: {
|
||||||
|
vendor: {
|
||||||
|
test: /[\\/]node_modules[\\/]/,
|
||||||
|
chunks: 'all',
|
||||||
|
name: 'vendor',
|
||||||
|
priority: 10,
|
||||||
|
enforce: true,
|
||||||
|
minChunks: 1,
|
||||||
|
maxSize: 3000000,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
minimizer: [
|
minimizer: [
|
||||||
new TerserJSPlugin({
|
new TerserJSPlugin({
|
||||||
cache: true,
|
cache: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user