Просмотр исходного кода

change environment variables pro only (#3951)

* change environment variables pro only

* change notes
陈小聪 6 лет назад
Родитель
Сommit
e245efe0cb
8 измененных файлов с 23 добавлено и 12 удалено
  1. 1 1
      .eslintrc.js
  2. 6 4
      config/config.js
  3. 5 2
      config/plugin.config.js
  4. 1 1
      jest.config.js
  5. 1 1
      package.json
  6. 5 1
      src/layouts/BasicLayout.js
  7. 2 1
      src/models/setting.js
  8. 2 1
      src/utils/authority.js

+ 1 - 1
.eslintrc.js

@@ -10,7 +10,7 @@ module.exports = {
     jasmine: true,
   },
   globals: {
-    APP_TYPE: true,
+    ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION: true, // preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。
     page: true,
   },
   rules: {

+ 6 - 4
config/config.js

@@ -6,7 +6,8 @@ import defaultSettings from '../src/defaultSettings';
 import slash from 'slash2';
 
 const { pwa, primaryColor } = defaultSettings;
-const { APP_TYPE, TEST } = process.env;
+// preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。
+const { ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION, TEST } = process.env;
 
 const plugins = [
   [
@@ -48,8 +49,8 @@ const plugins = [
 ];
 
 // 针对 preview.pro.ant.design 的 GA 统计代码
-// 业务上不需要这个
-if (APP_TYPE === 'site') {
+// preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。
+if (ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site') {
   plugins.push([
     'umi-plugin-ga',
     {
@@ -62,7 +63,8 @@ export default {
   // add for transfer to umi
   plugins,
   define: {
-    APP_TYPE: APP_TYPE || '',
+    ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION:
+      ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION || '', // preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。
   },
   treeShaking: true,
   targets: {

+ 5 - 2
config/plugin.config.js

@@ -24,8 +24,11 @@ function getModulePackageName(module) {
 }
 
 export default config => {
-  // pro 和 开发环境再添加这个插件
-  if (process.env.APP_TYPE === 'site' || process.env.NODE_ENV !== 'production') {
+  // preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。
+  if (
+    process.env.ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site' ||
+    process.env.NODE_ENV !== 'production'
+  ) {
     // 将所有 less 合并为一个供 themePlugin使用
     const outFile = path.join(__dirname, '../.temp/ant-design-pro.less');
     const stylesDir = path.join(__dirname, '../src/');

+ 1 - 1
jest.config.js

@@ -2,6 +2,6 @@ module.exports = {
   testURL: 'http://localhost:8000',
   preset: 'jest-puppeteer',
   globals: {
-    APP_TYPE: false,
+    ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION: false, // preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。
   },
 };

+ 1 - 1
package.json

@@ -23,7 +23,7 @@
     "lint:prettier": "check-prettier lint",
     "lint:style": "stylelint 'src/**/*.less' --syntax less",
     "prettier": "node ./scripts/prettier.js",
-    "start": "cross-env APP_TYPE=site umi dev",
+    "start": "cross-env ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION=site umi dev",
     "start:no-mock": "cross-env MOCK=none umi dev",
     "test": "umi test",
     "test:all": "node ./tests/run-tests.js",

+ 5 - 1
src/layouts/BasicLayout.js

@@ -90,7 +90,11 @@ class BasicLayout extends React.Component {
   renderSettingDrawer = () => {
     // Do not render SettingDrawer in production
     // unless it is deployed in preview.pro.ant.design as demo
-    if (process.env.NODE_ENV === 'production' && APP_TYPE !== 'site') {
+    // preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。
+    if (
+      process.env.NODE_ENV === 'production' &&
+      ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION !== 'site'
+    ) {
       return null;
     }
     return <SettingDrawer />;

+ 2 - 1
src/models/setting.js

@@ -4,7 +4,8 @@ import defaultSettings from '../defaultSettings';
 let lessNodesAppended;
 const updateTheme = primaryColor => {
   // Don't compile less in production!
-  if (APP_TYPE !== 'site') {
+  // preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。
+  if (ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION !== 'site') {
     return;
   }
   // Determine if the component is remounted

+ 2 - 1
src/utils/authority.js

@@ -13,7 +13,8 @@ export function getAuthority(str) {
   if (typeof authority === 'string') {
     return [authority];
   }
-  if (!authority && APP_TYPE === 'site') {
+  // preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。
+  if (!authority && ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site') {
     return ['admin'];
   }
   return authority;