Kaynağa Gözat

fix: add plugin to fix externals(react、react-dom)

lanjianrong 4 yıl önce
ebeveyn
işleme
8c5359327b
3 değiştirilmiş dosya ile 21 ekleme ve 18 silme
  1. 1 0
      README.md
  2. 5 18
      config/config.ts
  3. 15 0
      plugin.ts

+ 1 - 0
README.md

@@ -5,6 +5,7 @@
  2. locales/zh-CH/menu.js要加上对应国际化配置。
 3. 本项目使用@umijs/plugin-dva整合数据流进行全局状态管理, [详见](https://umijs.org/docs/max/dva)。
 4. 开发文档完全按照umi4官方规范进行, [详见](https://umijs.org/docs/guides/prepare)
+ 1. 样式使用unocss,预设是[windicss](https://windicss.org/guide/)的样式, vscode安装UnoCSS插件。
 
 ## 安装依赖
 

+ 5 - 18
config/config.ts

@@ -56,7 +56,6 @@ export default defineConfig({
       }
     }
   },
-  // alias: { antd: dirname(require.resolve('antd/package.json')) },
   srcTranspiler: 'esbuild',
   fastRefresh: true,
   unocss: {
@@ -77,8 +76,6 @@ export default defineConfig({
   proxy: proxy[REACT_APP_ENV || 'dev'],
   manifest: { basePath: '/' },
   extraBabelPlugins: [
-    '@babel/plugin-proposal-nullish-coalescing-operator',
-    '@babel/plugin-proposal-optional-chaining',
     [
       'import',
       {
@@ -97,19 +94,9 @@ export default defineConfig({
       },
       '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'
-  //       ]
+  ],
+  externals: {
+    react: 'React',
+    'react-dom': 'ReactDOM'
+  }
 })

+ 15 - 0
plugin.ts

@@ -0,0 +1,15 @@
+import { IApi } from '@umijs/max'
+
+export default (api: IApi) => {
+  api.addHTMLHeadScripts(() => {
+    return 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'
+        ]
+  })
+}