Przeglądaj źródła

refactor: upgrade to umi@4.0.3

lanjianrong 4 lat temu
rodzic
commit
22a4a5a496
3 zmienionych plików z 113 dodań i 113 usunięć
  1. 0 111
      config/config.js
  2. 111 0
      config/config.ts
  3. 2 2
      package.json

+ 0 - 111
config/config.js

@@ -1,111 +0,0 @@
-// https://umijs.org/config/
-
-import { defineConfig } from '@umijs/max'
-import defaultSettings from './defaultSettings'
-import proxy from './proxy'
-import routes from './routes'
-
-const CompressionPlugin = require('compression-webpack-plugin')
-const prodGzipList = ['js', 'css', 'html']
-const { REACT_APP_ENV } = process.env
-export default defineConfig({
-  plugins: [require.resolve('@umijs/plugins/dist/unocss')],
-  npmClient: 'pnpm',
-  hash: true,
-  antd: {},
-  model: {},
-  moment2dayjs: {},
-  request: {},
-  initialState: {},
-  access: {},
-  dva: {},
-  mfsu: {},
-  srcTranspiler: 'esbuild',
-  fastRefresh: true,
-  unocss: {
-    watch: ['src/pages/**/*.{jsx,tsx,less}', 'src/components/**/*.{jsx,tsx,less}'] // 添加其他包含 unocss 的 classname 的文件目录
-  },
-  // Fast Refresh 热更新
-  theme: { 'primary-color': '#886ab5' },
-  layout: {},
-  locale: {
-    default: 'zh-CN',
-    antd: false,
-    baseNavigator: false
-  },
-  define: { REACT_APP_ENV: REACT_APP_ENV || false },
-  targets: { ie: 11 },
-  routes,
-  title: false,
-  proxy: proxy[REACT_APP_ENV || 'dev'],
-  manifest: { basePath: '/' },
-  extraBabelPlugins: [
-    '@babel/plugin-proposal-nullish-coalescing-operator',
-    '@babel/plugin-proposal-optional-chaining',
-    [
-      'import',
-      {
-        libraryName: '@icon-park/react',
-        libraryDirectory: 'es/icons',
-        camel2DashComponentName: false
-      },
-      '@icon-park/react'
-    ],
-    [
-      'import',
-      {
-        libraryName: 'antd',
-        libraryDirectory: 'es',
-        style: 'less'
-      },
-      'antd'
-    ]
-  ],
-  externals: {
-    react: 'React',
-    'react-dom': 'ReactDOM'
-  },
-  headScripts:
-    process.env.NODE_ENV === 'development'
-      ? [
-          'https://d2.smartcost.com.cn/cach/cld/react18.1.0/react.development.js',
-          'https://d2.smartcost.com.cn/cach/cld/react18.1.0/react-dom.development.js'
-        ]
-      : [
-          'https://d2.smartcost.com.cn/cach/cld/react18.1.0/react.production.min.js',
-          'https://d2.smartcost.com.cn/cach/cld/react18.1.0/react-dom.production.min.js'
-        ],
-
-  chainWebpack(config, { env }) {
-    if (env === 'production') {
-      // config.merge({
-      //   optimization: {
-      //     minimize: true,
-      //     splitChunks: {
-      //       chunks: 'all',
-      //       minSize: 30000,
-      //       minChunks: 2,
-      //       automaticNameDelimiter: '.',
-      //       cacheGroups: {
-      //         vendor: {
-      //           name: 'vendors',
-      //           test: ({ resource }) => /[\\/]node_modules[\\/]/.test(resource),
-      //           chunks: 'all',
-      //           priority: 20
-      //         }
-      //       }
-      //     }
-      //   }
-      // })
-      config.plugin('compression-webpack-plugin').use(
-        new CompressionPlugin({
-          // filename: 文件名称,这里我们不设置,让它保持和未压缩的文件同一个名称
-          algorithm: 'gzip', // 指定生成gzip格式
-          test: new RegExp('\\.(' + prodGzipList.join('|') + ')$'), // 匹配哪些格式文件需要压缩
-          threshold: 10000, //对超过10k的数据进行压缩
-          minRatio: 0.6 // 压缩比例,值为0 ~ 1
-        })
-      )
-    }
-  }
-})

+ 111 - 0
config/config.ts

@@ -0,0 +1,111 @@
+// https://umijs.org/config/
+
+import { defineConfig } from '@umijs/max'
+import defaultSettings from './defaultSettings'
+import proxy from './proxy'
+import routes from './routes'
+
+const CompressionPlugin = require('compression-webpack-plugin')
+const prodGzipList = ['js', 'css', 'html']
+const { REACT_APP_ENV } = process.env
+export default defineConfig({
+  plugins: [require.resolve('@umijs/plugins/dist/unocss')],
+  npmClient: 'pnpm',
+  hash: true,
+  antd: {},
+  model: {},
+  moment2dayjs: {},
+  request: {},
+  initialState: {},
+  access: {},
+  dva: {},
+  mfsu: {
+    chainWebpack(config, { env }) {
+      if (env === 'production') {
+        // config.merge({
+        //   optimization: {
+        //     minimize: true,
+        //     splitChunks: {
+        //       chunks: 'all',
+        //       minSize: 30000,
+        //       minChunks: 2,
+        //       automaticNameDelimiter: '.',
+        //       cacheGroups: {
+        //         vendor: {
+        //           name: 'vendors',
+        //           test: ({ resource }) => /[\\/]node_modules[\\/]/.test(resource),
+        //           chunks: 'all',
+        //           priority: 20
+        //         }
+        //       }
+        //     }
+        //   }
+        // })
+        config.plugin('compression-webpack-plugin').use(
+          new CompressionPlugin({
+            // filename: 文件名称,这里我们不设置,让它保持和未压缩的文件同一个名称
+            algorithm: 'gzip', // 指定生成gzip格式
+            test: new RegExp('\\.(' + prodGzipList.join('|') + ')$'), // 匹配哪些格式文件需要压缩
+            threshold: 10000, //对超过10k的数据进行压缩
+            minRatio: 0.6 // 压缩比例,值为0 ~ 1
+          })
+        )
+      }
+    }
+  },
+  srcTranspiler: 'esbuild',
+  fastRefresh: true,
+  unocss: {
+    watch: ['src/pages/**/*.{jsx,tsx,less}', 'src/components/**/*.{jsx,tsx,less}'] // 添加其他包含 unocss 的 classname 的文件目录
+  },
+  // Fast Refresh 热更新
+  theme: { 'primary-color': '#886ab5' },
+  layout: {},
+  locale: {
+    default: 'zh-CN',
+    antd: false,
+    baseNavigator: false
+  },
+  define: { REACT_APP_ENV: REACT_APP_ENV || false },
+  targets: { ie: 11 },
+  routes,
+  title: false,
+  proxy: proxy[REACT_APP_ENV || 'dev'],
+  manifest: { basePath: '/' },
+  extraBabelPlugins: [
+    '@babel/plugin-proposal-nullish-coalescing-operator',
+    '@babel/plugin-proposal-optional-chaining',
+    [
+      'import',
+      {
+        libraryName: '@icon-park/react',
+        libraryDirectory: 'es/icons',
+        camel2DashComponentName: false
+      },
+      '@icon-park/react'
+    ],
+    [
+      'import',
+      {
+        libraryName: 'antd',
+        libraryDirectory: 'es',
+        style: 'less'
+      },
+      'antd'
+    ]
+  ]
+  // externals: {
+  //   react: 'React',
+  //   'react-dom': 'ReactDOM'
+  // },
+  // headScripts:
+  //   process.env.NODE_ENV === 'development'
+  //     ? [
+  //         'https://d2.smartcost.com.cn/cach/cld/react18.1.0/react.development.js',
+  //         'https://d2.smartcost.com.cn/cach/cld/react18.1.0/react-dom.development.js'
+  //       ]
+  //     : [
+  //         'https://d2.smartcost.com.cn/cach/cld/react18.1.0/react.production.min.js',
+  //         'https://d2.smartcost.com.cn/cach/cld/react18.1.0/react-dom.production.min.js'
+  //       ],
+})

+ 2 - 2
package.json

@@ -33,8 +33,8 @@
     "@ant-design/pro-layout": "6.38.8",
     "@ant-design/pro-table": "2.76.3",
     "@icon-park/react": "^1.3.3",
-    "@umijs/max": "4.0.2",
-    "@umijs/plugins": "4.0.2",
+    "@umijs/max": "4.0.3",
+    "@umijs/plugins": "4.0.3",
     "ahooks": "^3.4.1",
     "antd": "4.21.0",
     "antd-img-crop": "^3.16.0",