From 2759f6c82e24655400fbe8df81bf8fdabb42789b Mon Sep 17 00:00:00 2001 From: Calvin Lai Date: Fri, 23 Feb 2018 16:59:34 -0500 Subject: [PATCH] feat: map client env values in webpack config instead of root config --- config/index.js | 13 ++++--------- webpack/base.js | 6 ++++-- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/config/index.js b/config/index.js index 1bbb101..c75109d 100644 --- a/config/index.js +++ b/config/index.js @@ -1,5 +1,3 @@ -const { mapValues, keyBy } = require('lodash'); - module.exports = { // Enable or disable server-side rendering enableSSR: true, @@ -12,13 +10,10 @@ module.exports = { // in node.js. // // **WARNING**: Be careful not to expose any secrets here! - clientEnv: mapValues( - keyBy([ - 'NODE_ENV', - 'APPLICATION_BASE_URL' - ]), - (env) => JSON.stringify(process.env[env]) - ), + clientEnvVars: [ + 'NODE_ENV', + 'APPLICATION_BASE_URL' + ], /* The identifier to use for css-modules. */ diff --git a/webpack/base.js b/webpack/base.js index b0fc729..bf69831 100644 --- a/webpack/base.js +++ b/webpack/base.js @@ -4,11 +4,11 @@ if (isDev) require('dotenv').load(); import yn from 'yn'; import path from 'path'; import webpack from 'webpack'; -import mapValues from 'lodash/mapValues'; import IsoPlugin from 'webpack-isomorphic-tools/plugin'; import ExtractTextPlugin from 'extract-text-webpack-plugin'; import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'; import { ReactLoadablePlugin } from 'react-loadable/webpack'; +import { mapValues, keyBy } from 'lodash'; import config from '../config'; let ssr = yn(process.env.SSR) || false; @@ -24,7 +24,9 @@ let plugins = [ extractTextPlugin, new webpack.ContextReplacementPlugin(/moment[/\\]locale$/, /en|es/), new webpack.DefinePlugin({ - 'process.env': config.clientEnv + 'process.env': mapValues(keyBy(config.clientEnvVars), (env) => { + return JSON.stringify(process.env[env]); + }) }) ];