Replies: 1 comment
-
umi 3 不维护了,建议升级到 umi 4 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
umi版本:3.5.0
config配置开启dynamicImport以后打包结果还是没有拆分,路由不是一个个页面配置的,是通过require.context('@/pages', true, /index(.tsx)$/)根据文件路径自动生成的。config配置如下:
import { defineConfig } from 'umi';
import defaultSettings from './defaultSettings';
import proxy from './proxy';
import routes from './routes';
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
const { REACT_APP_ENV } = process.env;
export default defineConfig({
hash: true,
history: {
type: 'hash',
},
antd: {},
dva: {
hmr: true,
},
layout: {
locale: false,
siderWidth: 240,
...defaultSettings,
},
locale: {
default: 'zh-CN',
antd: false,
baseNavigator: false,
},
dynamicImport: {
loading: '@ant-design/pro-layout/es/PageLoading',
},
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true,
},
},
targets: {
ie: 11,
},
routes,
theme: {
'primary-color': defaultSettings.primaryColor,
},
esbuild: {},
title: false,
ignoreMomentLocale: true,
proxy: proxy[REACT_APP_ENV || 'dev'],
manifest: {
basePath: '/',
},
lessLoader: {
modifyVars: {
'root-entry-name': 'default', // 解决antd 4.17.0-alpha.9 bug 官方发布正式版后可尝试移除
},
},
fastRefresh: {},
openAPI: [],
nodeModulesTransform: { type: 'none' },
webpack5: {},
copy: [
{ from: 'node_modules/@liveqing/liveplayer/dist/element/liveplayer.swf', to: '/' },
{ from: 'node_modules/@liveqing/liveplayer/dist/element/crossdomain.xml', to: '/' },
{ from: 'node_modules/@liveqing/liveplayer/dist/element/liveplayer-element.min.js', to: '/' },
],
headScripts: [{ src: './liveplayer-element.min.js', defer: true }],
// chunks:['monaco-editor','ant-design','utils','vendors', 'device','retrospect','umi'],
chainWebpack(config, { env, webpack, createCSSRule }) {
config.plugin('monaco-editor').use(
new MonacoWebpackPlugin({
languages: ['json', 'javascript', 'typescript', 'sql'],
}),
);
config.module.rule('mjs-rule').test(/.m?js/).resolve.set('fullySpecified', false);
/*config.merge({
optimization: {
splitChunks: {
automaticNameDelimiter: '.',//指定了拆分后的文件名的分隔符
chunks: 'all',
// minSize: 30000,//拆分后的代码块最小大小
// chunks: (chunk:any) => ChunksIgnoreList.filter((item) => item.includes(chunk.name)).length === 0,
// minSize: 30000,//拆分后的代码块最小大小30k
// minChunks:3,//一个模块被多少个入口文件引用时才会被拆分
// maxSize: 0,
// // name:true,
// maxAsyncRequests: 30,//最大异步请求数
// maxInitialRequests: 30,//最大初始请求数
// enforceSizeThreshold: 50000,
// maxSize: 0,
// minChunks:3,//一个模块被多少个入口文件引用时才会被拆分
cacheGroups: {
monaco: {
name: 'monaco-editor',
// chunks: 'all',
test: /[\/]node_modules\/[\/]/,
priority: 10,
enforce: true,
reuseExistingChunk: true,
},
antd: {
name: 'ant-design',
// chunks: 'async',
test: /[\/]node_modules\/[\/]/,
priority: 9,
enforce: true,
reuseExistingChunk: true,
},
utils: {
name: 'utils',
// chunks: 'async',
// test: /[\/]node_modules\/[\/]/,
test: /[\/]node_modules\/[\/]/,
},
});
打包结果如下:
Beta Was this translation helpful? Give feedback.
All reactions