From db30e421c37fabb7188f2a7a6515cbb6df37ddc5 Mon Sep 17 00:00:00 2001 From: EGOIST <0x142857@gmail.com> Date: Tue, 5 Sep 2017 13:56:09 +0800 Subject: [PATCH] stop overriding process.env --- packages/poi/lib/create-config.js | 13 +++++++++---- packages/poi/lib/utils.js | 7 +++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/poi/lib/create-config.js b/packages/poi/lib/create-config.js index 06e0bdd6..79ec85d4 100644 --- a/packages/poi/lib/create-config.js +++ b/packages/poi/lib/create-config.js @@ -15,7 +15,8 @@ const { getPublicPath, ownDir, inferProductionValue, - stringifyObject + stringifyObject, + getFullEnvString } = require('./utils') const logger = require('./logger') const cssLoaders = require('./webpack/css-loaders') @@ -193,9 +194,13 @@ module.exports = function ({ .use(PathsCaseSensitivePlugin) config.plugin('constants') - .use(webpack.DefinePlugin, [merge({ - 'process.env': env - }, define && stringifyObject(define))]) + .use(webpack.DefinePlugin, [ + merge( + // { foo: '"foo"' } => { 'process.env.foo': '"foo"' } + getFullEnvString(env), + define && stringifyObject(define) + ) + ]) config.plugin('fancy-log') .use(FancyLogPlugin, [ diff --git a/packages/poi/lib/utils.js b/packages/poi/lib/utils.js index 5ba6e108..1cf543ed 100644 --- a/packages/poi/lib/utils.js +++ b/packages/poi/lib/utils.js @@ -95,3 +95,10 @@ exports.createSet = function (value) { exports.unspecifiedAddress = function (host) { return host === '0.0.0.0' || host === '::' } + +exports.getFullEnvString = function (env) { + return Object.keys(env).reduce((res, key) => { + res[`process.env.${key}`] = env[key] + return res + }, {}) +}