From e245efe0cbd72eda96849e8f0f4868aa8fdd2097 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=B0=8F=E8=81=AA?= Date: Fri, 12 Apr 2019 22:26:28 +0800 Subject: [PATCH] change environment variables pro only (#3951) * change environment variables pro only * change notes --- .eslintrc.js | 2 +- config/config.js | 10 ++++++---- config/plugin.config.js | 7 +++++-- jest.config.js | 2 +- package.json | 2 +- src/layouts/BasicLayout.js | 6 +++++- src/models/setting.js | 3 ++- src/utils/authority.js | 3 ++- 8 files changed, 23 insertions(+), 12 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index aeeca68f..dbe7d4d3 100644 --- a/.eslintrc.js +++ b/.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: { diff --git a/config/config.js b/config/config.js index c68107bd..d939eac9 100644 --- a/config/config.js +++ b/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: { diff --git a/config/plugin.config.js b/config/plugin.config.js index 2273586e..59ce550f 100644 --- a/config/plugin.config.js +++ b/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/'); diff --git a/jest.config.js b/jest.config.js index a1d8c22c..ba22e52a 100644 --- a/jest.config.js +++ b/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 专用环境变量,请不要在你的项目中使用它。 }, }; diff --git a/package.json b/package.json index c4bf3e32..3678c8ca 100644 --- a/package.json +++ b/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", diff --git a/src/layouts/BasicLayout.js b/src/layouts/BasicLayout.js index 249ff31f..686742dd 100644 --- a/src/layouts/BasicLayout.js +++ b/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 ; diff --git a/src/models/setting.js b/src/models/setting.js index 171da48d..3956ed3d 100644 --- a/src/models/setting.js +++ b/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 diff --git a/src/utils/authority.js b/src/utils/authority.js index 396a9fbd..bb1aa23b 100644 --- a/src/utils/authority.js +++ b/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;