|
@@ -1,12 +1,9 @@
|
|
|
// https://umijs.org/config/
|
|
// https://umijs.org/config/
|
|
|
-// import { cleanupSVG, isEmptyColor, parseColors, runSVGO, SVG } from '@iconify/tools';
|
|
|
|
|
import { defineConfig } from '@umijs/max';
|
|
import { defineConfig } from '@umijs/max';
|
|
|
-import { glob } from 'glob';
|
|
|
|
|
-import path, { join } from 'path';
|
|
|
|
|
-// import { FileSystemIconLoader } from 'unplugin-icons/loaders';
|
|
|
|
|
-// import Icons from 'unplugin-icons/webpack';
|
|
|
|
|
import dayjs from 'dayjs';
|
|
import dayjs from 'dayjs';
|
|
|
import fs from 'fs';
|
|
import fs from 'fs';
|
|
|
|
|
+import { glob } from 'glob';
|
|
|
|
|
+import path, { join } from 'path';
|
|
|
import defaultSettings from './defaultSettings';
|
|
import defaultSettings from './defaultSettings';
|
|
|
import proxy from './proxy';
|
|
import proxy from './proxy';
|
|
|
import routes from './routes';
|
|
import routes from './routes';
|
|
@@ -113,11 +110,39 @@ export default defineConfig({
|
|
|
href: `/favicon-${envConfig.REACT_APP_ID}.ico`,
|
|
href: `/favicon-${envConfig.REACT_APP_ID}.ico`,
|
|
|
},
|
|
},
|
|
|
],
|
|
],
|
|
|
- // /** unplugin-icons 加载本地图标 */
|
|
|
|
|
- // alias: {
|
|
|
|
|
- // '~icons': '.icons',
|
|
|
|
|
- // },
|
|
|
|
|
|
|
+ alias: {
|
|
|
|
|
+ '@svgs': path.resolve(process.cwd(), 'svgs'),
|
|
|
|
|
+ },
|
|
|
chainWebpack(memo) {
|
|
chainWebpack(memo) {
|
|
|
|
|
+ const svgsDir = path.resolve(process.cwd(), 'svgs');
|
|
|
|
|
+
|
|
|
|
|
+ // 将 svgs/ 目录从所有能匹配 .svg 的规则中排除(包括 asset/resource 类型规则和 svgo-loader)
|
|
|
|
|
+ Object.values(memo.module.rules.entries()).forEach((rule: any) => {
|
|
|
|
|
+ const testRegex = rule.get?.('test');
|
|
|
|
|
+ if (testRegex instanceof RegExp && testRegex.test('file.svg')) {
|
|
|
|
|
+ rule.exclude.add(svgsDir);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ const uses = rule.uses?.entries?.();
|
|
|
|
|
+ if (!uses) return;
|
|
|
|
|
+ Object.values(uses).forEach((use: any) => {
|
|
|
|
|
+ if ((use.get?.('loader') ?? '').includes('svgo-loader')) {
|
|
|
|
|
+ rule.exclude.add(svgsDir);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // SVG icon loader:自动处理 svgs/ 目录,无需手动运行 convert-svg-icon
|
|
|
|
|
+ memo.module
|
|
|
|
|
+ .rule('svgs-iconify')
|
|
|
|
|
+ .test(/\.svg$/)
|
|
|
|
|
+ .include.add(svgsDir)
|
|
|
|
|
+ .end()
|
|
|
|
|
+ .type('javascript/auto')
|
|
|
|
|
+ .use('iconify-svg-loader')
|
|
|
|
|
+ .loader(path.resolve(process.cwd(), 'tools/svgIconLoader.cjs'))
|
|
|
|
|
+ .end();
|
|
|
|
|
+
|
|
|
// 在生产环境构建时生成 version.json 文件
|
|
// 在生产环境构建时生成 version.json 文件
|
|
|
if (REACT_APP_ENV === 'prod' || REACT_APP_ENV === 'test' || REACT_APP_ENV === 'dev') {
|
|
if (REACT_APP_ENV === 'prod' || REACT_APP_ENV === 'test' || REACT_APP_ENV === 'dev') {
|
|
|
memo.plugin('generate-version-file').use(
|
|
memo.plugin('generate-version-file').use(
|
|
@@ -125,7 +150,7 @@ export default defineConfig({
|
|
|
apply(compiler: any) {
|
|
apply(compiler: any) {
|
|
|
compiler.hooks.beforeCompile.tapAsync(
|
|
compiler.hooks.beforeCompile.tapAsync(
|
|
|
'GenerateVersionFilePlugin',
|
|
'GenerateVersionFilePlugin',
|
|
|
- (params: any, callback: any) => {
|
|
|
|
|
|
|
+ (_params: any, callback: any) => {
|
|
|
try {
|
|
try {
|
|
|
const publicDir = path.join(process.cwd(), 'public');
|
|
const publicDir = path.join(process.cwd(), 'public');
|
|
|
if (!fs.existsSync(publicDir)) {
|
|
if (!fs.existsSync(publicDir)) {
|
|
@@ -158,46 +183,6 @@ export default defineConfig({
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // chainWebpack(memo) {
|
|
|
|
|
- // memo.plugin('unplugin-icons').use(
|
|
|
|
|
- // Icons({
|
|
|
|
|
- // compiler: 'jsx',
|
|
|
|
|
- // jsx: 'react',
|
|
|
|
|
- // autoInstall: true,
|
|
|
|
|
- // scale: 1,
|
|
|
|
|
- // defaultClass: 'iconify-icon',
|
|
|
|
|
- // customCollections: {
|
|
|
|
|
- // // 自定义单色图标集合
|
|
|
|
|
- // 'custom-sc': FileSystemIconLoader(
|
|
|
|
|
- // // 单色 svg 文件目录
|
|
|
|
|
- // './svgs/single-color',
|
|
|
|
|
- // (svg) => {
|
|
|
|
|
- // // 将 SVG 字符串转换为 SVG 实例
|
|
|
|
|
- // const svgObj = new SVG(svg);
|
|
|
|
|
- // cleanupSVG(svgObj);
|
|
|
|
|
- // parseColors(svgObj, {
|
|
|
|
|
- // defaultColor: 'currentColor',
|
|
|
|
|
- // callback: (attr, colorStr, color) => {
|
|
|
|
|
- // return !color || isEmptyColor(color) ? colorStr : 'currentColor';
|
|
|
|
|
- // },
|
|
|
|
|
- // });
|
|
|
|
|
- // runSVGO(svgObj);
|
|
|
|
|
- // return svgObj.toMinifiedString();
|
|
|
|
|
- // },
|
|
|
|
|
- // ),
|
|
|
|
|
- // // 自定义多色图标集合
|
|
|
|
|
- // 'custom-mc': FileSystemIconLoader('./svgs/multi-color', (svg) => {
|
|
|
|
|
- // // 将 SVG 字符串转换为 SVG 实例
|
|
|
|
|
- // const svgObj = new SVG(svg);
|
|
|
|
|
- // cleanupSVG(svgObj);
|
|
|
|
|
- // runSVGO(svgObj);
|
|
|
|
|
- // return svgObj.toMinifiedString();
|
|
|
|
|
- // }),
|
|
|
|
|
- // },
|
|
|
|
|
- // }),
|
|
|
|
|
- // );
|
|
|
|
|
- // return memo;
|
|
|
|
|
- // },
|
|
|
|
|
return memo;
|
|
return memo;
|
|
|
},
|
|
},
|
|
|
|
|
|
|
@@ -349,6 +334,8 @@ export default defineConfig({
|
|
|
mfsu: {
|
|
mfsu: {
|
|
|
strategy: 'normal',
|
|
strategy: 'normal',
|
|
|
shared: {
|
|
shared: {
|
|
|
|
|
+ react: { singleton: true, eager: true, requiredVersion: false },
|
|
|
|
|
+ 'react-dom': { singleton: true, eager: true, requiredVersion: false },
|
|
|
'lodash-es': { singleton: true, eager: true, requiredVersion: false },
|
|
'lodash-es': { singleton: true, eager: true, requiredVersion: false },
|
|
|
ramda: { singleton: true, eager: true, requiredVersion: false },
|
|
ramda: { singleton: true, eager: true, requiredVersion: false },
|
|
|
},
|
|
},
|