From dec233ca2a677ed464edabeaf1c30c58e29d69f8 Mon Sep 17 00:00:00 2001 From: maxceem Date: Mon, 18 Jan 2021 11:10:27 +0200 Subject: [PATCH 1/2] chore: use "APPENV" to config environment --- config/{development.js => dev.js} | 0 config/index.js | 6 +++--- config/{production.js => prod.js} | 0 3 files changed, 3 insertions(+), 3 deletions(-) rename config/{development.js => dev.js} (100%) rename config/{production.js => prod.js} (100%) diff --git a/config/development.js b/config/dev.js similarity index 100% rename from config/development.js rename to config/dev.js diff --git a/config/index.js b/config/index.js index d89d9220..0de81581 100644 --- a/config/index.js +++ b/config/index.js @@ -1,11 +1,11 @@ /* global process */ module.exports = (() => { - const env = process.env.NODE_ENV || "development"; + const env = process.env.APPENV || "dev"; // for security reason don't let to require any arbitrary file defined in process.env - if (["production", "development"].indexOf(env) < 0) { - return require("./development"); + if (["prod", "dev"].indexOf(env) < 0) { + return require("./dev"); } return require("./" + env); diff --git a/config/production.js b/config/prod.js similarity index 100% rename from config/production.js rename to config/prod.js From be2d73c3f65b5d53ea782644707d2a28ecc123fd Mon Sep 17 00:00:00 2001 From: yoution Date: Tue, 19 Jan 2021 12:33:11 +0800 Subject: [PATCH 2/2] fix: issue #13 --- babel.config.js | 59 +++++++++++++++++++++++++++++++++++++++++++++++ babel.config.json | 51 ---------------------------------------- webpack.config.js | 5 +++- 3 files changed, 63 insertions(+), 52 deletions(-) create mode 100644 babel.config.js delete mode 100644 babel.config.json diff --git a/babel.config.js b/babel.config.js new file mode 100644 index 00000000..07815e13 --- /dev/null +++ b/babel.config.js @@ -0,0 +1,59 @@ +module.exports = function (api) { + const isProd = process.env.APPMODE === "production"; + api.cache(!isProd); + + const generateScopedName = isProd + ? "[hash:base64:6]" + : "teams_[path][name]___[local]___[hash:base64:6]"; + return { + presets: ["@babel/preset-env", "@babel/preset-react"], + plugins: [ + [ + "@babel/plugin-transform-runtime", + { + useESModules: true, + regenerator: false, + }, + ], + [ + "react-css-modules", + { + filetypes: { + ".scss": { + syntax: "postcss-scss", + }, + }, + generateScopedName, + }, + ], + "inline-react-svg", + ], + env: { + test: { + presets: [ + [ + "@babel/preset-env", + { + targets: "current node", + }, + ], + ], + plugins: [ + [ + "module-resolver", + { + alias: { + styles: "./src/styles", + components: "./src/components", + hooks: "./src/hooks", + utils: "./src/utils", + constants: "./src/constants", + services: "./src/services", + }, + }, + ], + ], + }, + }, + }; +}; diff --git a/babel.config.json b/babel.config.json deleted file mode 100644 index 00432fb5..00000000 --- a/babel.config.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "presets": [ - "@babel/preset-env", - "@babel/preset-react" - ], - "plugins": [ - [ - "@babel/plugin-transform-runtime", - { - "useESModules": true, - "regenerator": false - } - ], - [ - "react-css-modules", - { - "filetypes": { - ".scss": { - "syntax": "postcss-scss" - } - }, - "generateScopedName": "teams_[path][name]___[local]___[hash:base64:6]" - } - ], - "inline-react-svg" - ], - "env": { - "test": { - "presets": [ - [ - "@babel/preset-env", - { - "targets": "current node" - } - ] - ], - "plugins": [ - ["module-resolver", { - "alias": { - "styles": "./src/styles", - "components": "./src/components", - "hooks": "./src/hooks", - "utils": "./src/utils", - "constants": "./src/constants", - "services": "./src/services" - } - }] - ] - } - } -} diff --git a/webpack.config.js b/webpack.config.js index 53bce9e0..5a4d4326 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -4,7 +4,10 @@ const singleSpaDefaults = require("webpack-config-single-spa-react"); const path = require("path"); const autoprefixer = require("autoprefixer"); -const cssLocalIdent = "teams_[path][name]___[local]___[hash:base64:6]"; + +const cssLocalIdent = process.env.APPMODE === "production" + ? "[hash:base64:6]" + : "teams_[path][name]___[local]___[hash:base64:6]"; module.exports = (webpackConfigEnv) => { const defaultConfig = singleSpaDefaults({