Skip to content

Commit

Permalink
feat: map client env values in webpack config instead of root config
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinl committed Feb 24, 2018
1 parent c1fdf9d commit 2759f6c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
13 changes: 4 additions & 9 deletions config/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const { mapValues, keyBy } = require('lodash');

module.exports = {
// Enable or disable server-side rendering
enableSSR: true,
Expand All @@ -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.
*/
Expand Down
6 changes: 4 additions & 2 deletions webpack/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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]);
})
})
];

Expand Down

0 comments on commit 2759f6c

Please sign in to comment.