Commit 6e8bd92caddb40f9a490a0913bad4d31154b4f15
1 parent
590f1a01
💥 feat(config): 开发阶段懒编译
Showing
2 changed files
with
6 additions
and
106 deletions
config/config.ts
1 | 1 | import { defineConfig } from 'umi'; |
2 | 2 | import routers from './routers'; |
3 | 3 | import proxy from './proxy'; |
4 | -import webpackPlugin from './plugin.config'; | |
5 | 4 | |
6 | 5 | const { REACT_APP_ENV } = process.env; |
7 | 6 | |
... | ... | @@ -9,24 +8,19 @@ export default defineConfig({ |
9 | 8 | dva: { |
10 | 9 | hmr: true, |
11 | 10 | }, |
12 | - webpack5: {}, | |
11 | + webpack5: { lazyCompilation: {} }, | |
13 | 12 | fastRefresh: {}, |
14 | 13 | devtool: false, |
15 | - // umi routes: https://umijs.org/zh/guide/router.html | |
16 | 14 | routes: routers, |
17 | 15 | define: { |
18 | 16 | PROD_APP_ENV: (REACT_APP_ENV || 'dev') === 'prod', |
19 | 17 | GRAY_TAG: '', |
20 | 18 | }, |
21 | - // Theme for antd: https://ant.design/docs/react/customize-theme-cn | |
22 | 19 | theme: { |
23 | 20 | 'primary-color': (REACT_APP_ENV || 'dev') === 'prod' ? '#1890FF' : '#FAAD14', |
24 | 21 | }, |
25 | - // layout: defaultSettings, | |
26 | 22 | locale: { |
27 | - // default zh-CN | |
28 | 23 | default: 'zh-CN', |
29 | - // default true, when it is true, will use `navigator.language` overwrite default | |
30 | 24 | antd: true, |
31 | 25 | baseNavigator: true, |
32 | 26 | }, |
... | ... | @@ -58,5 +52,9 @@ export default defineConfig({ |
58 | 52 | type: process.env.NODE_ENV == 'development' ? 'none' : 'all', |
59 | 53 | exclude: [], |
60 | 54 | }, |
61 | - chainWebpack: webpackPlugin, | |
55 | + chainWebpack(config: any) { | |
56 | + config.set('experiments', { | |
57 | + asyncWebAssembly: true, | |
58 | + }); | |
59 | + }, | |
62 | 60 | }); | ... | ... |
config/plugin.config.ts deleted
1 | -import ThemeColorReplacer from "webpack-theme-color-replacer"; | |
2 | -import path from "path"; | |
3 | -import { generate } from "@ant-design/colors"; | |
4 | - | |
5 | -function getModulePackageName(module: { context: string }) { | |
6 | - if (!module.context) return null; | |
7 | - | |
8 | - const nodeModulesPath = path.join(__dirname, "../node_modules/"); | |
9 | - if (module.context.substring(0, nodeModulesPath.length) !== nodeModulesPath) { | |
10 | - return null; | |
11 | - } | |
12 | - | |
13 | - const moduleRelativePath = module.context.substring(nodeModulesPath.length); | |
14 | - const [moduleDirName] = moduleRelativePath.split(path.sep); | |
15 | - let packageName: string | null = moduleDirName; | |
16 | - // handle tree shaking | |
17 | - if (packageName && packageName.match("^_")) { | |
18 | - // eslint-disable-next-line prefer-destructuring | |
19 | - packageName = packageName.match(/^_(@?[^@]+)/)![1]; | |
20 | - } | |
21 | - return packageName; | |
22 | -} | |
23 | - | |
24 | -export default (config: any, { env, webpack, createCSSRule }: any) => { | |
25 | - // preview.pro.ant.design only do not use in your production; | |
26 | - if ( | |
27 | - process.env.ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === "site" || | |
28 | - process.env.NODE_ENV !== "production" | |
29 | - ) { | |
30 | - config.plugin("webpack-theme-color-replacer").use(ThemeColorReplacer, [ | |
31 | - { | |
32 | - fileName: "css/theme-colors-[contenthash:8].css", | |
33 | - matchColors: getAntdSerials("#1890ff"), // 主色系列 | |
34 | - // 改变样式选择器,解决样式覆盖问题 | |
35 | - changeSelector(selector: string): string { | |
36 | - switch (selector) { | |
37 | - case ".ant-calendar-today .ant-calendar-date": | |
38 | - return ":not(.ant-calendar-selected-date)" + selector; | |
39 | - case ".ant-btn:focus,.ant-btn:hover": | |
40 | - return ".ant-btn:focus:not(.ant-btn-primary),.ant-btn:hover:not(.ant-btn-primary)"; | |
41 | - case ".ant-btn.active,.ant-btn:active": | |
42 | - return ".ant-btn.active:not(.ant-btn-primary),.ant-btn:active:not(.ant-btn-primary)"; | |
43 | - default: | |
44 | - return selector; | |
45 | - } | |
46 | - }, | |
47 | - // isJsUgly: true, | |
48 | - }, | |
49 | - ]); | |
50 | - } | |
51 | - | |
52 | - config.set("experiments", { | |
53 | - asyncWebAssembly: true, | |
54 | - }); | |
55 | - | |
56 | - // optimize chunks | |
57 | - config.optimization | |
58 | - // share the same chunks across different modules | |
59 | - .runtimeChunk(false) | |
60 | - .splitChunks({ | |
61 | - chunks: "async", | |
62 | - maxInitialRequests: Infinity, | |
63 | - minSize: 0, | |
64 | - cacheGroups: { | |
65 | - vendors: { | |
66 | - test: (module: { context: string }) => { | |
67 | - const packageName = getModulePackageName(module) || ""; | |
68 | - if (packageName) { | |
69 | - return ["bizcharts", "gg-editor", "g6", "@antv", "gg-editor-core", "bizcharts-plugin-slider"].includes( | |
70 | - packageName | |
71 | - ); | |
72 | - } | |
73 | - return false; | |
74 | - }, | |
75 | - name(module: { context: string }) { | |
76 | - const packageName = getModulePackageName(module); | |
77 | - if (packageName) { | |
78 | - if (["bizcharts", "@antv_data-set"].indexOf(packageName) >= 0) { | |
79 | - return "viz"; // visualization package | |
80 | - } | |
81 | - } | |
82 | - return "misc"; | |
83 | - }, | |
84 | - }, | |
85 | - }, | |
86 | - }); | |
87 | -}; | |
88 | - | |
89 | -const getAntdSerials = (color: string) => { | |
90 | - const lightNum = 9; | |
91 | - const devide10 = 10; | |
92 | - // 淡化(即less的tint) | |
93 | - const lightens = new Array(lightNum).fill(undefined).map((_, i: number) => { | |
94 | - return ThemeColorReplacer.varyColor.lighten(color, i / devide10); | |
95 | - }); | |
96 | - const colorPalettes = generate(color); | |
97 | - return lightens.concat(colorPalettes); | |
98 | -}; |