Skip to content
This repository has been archived by the owner on Dec 6, 2021. It is now read-only.

Commit

Permalink
stop overriding process.env
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed Sep 5, 2017
1 parent cfaab2e commit db30e42
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/poi/lib/create-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const {
getPublicPath,
ownDir,
inferProductionValue,
stringifyObject
stringifyObject,
getFullEnvString
} = require('./utils')
const logger = require('./logger')
const cssLoaders = require('./webpack/css-loaders')
Expand Down Expand Up @@ -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, [
Expand Down
7 changes: 7 additions & 0 deletions packages/poi/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}, {})
}

0 comments on commit db30e42

Please sign in to comment.