Skip to content

Commit 2759f6c

Browse files
committed
feat: map client env values in webpack config instead of root config
1 parent c1fdf9d commit 2759f6c

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

config/index.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const { mapValues, keyBy } = require('lodash');
2-
31
module.exports = {
42
// Enable or disable server-side rendering
53
enableSSR: true,
@@ -12,13 +10,10 @@ module.exports = {
1210
// in node.js.
1311
//
1412
// **WARNING**: Be careful not to expose any secrets here!
15-
clientEnv: mapValues(
16-
keyBy([
17-
'NODE_ENV',
18-
'APPLICATION_BASE_URL'
19-
]),
20-
(env) => JSON.stringify(process.env[env])
21-
),
13+
clientEnvVars: [
14+
'NODE_ENV',
15+
'APPLICATION_BASE_URL'
16+
],
2217

2318
/* The identifier to use for css-modules.
2419
*/

webpack/base.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ if (isDev) require('dotenv').load();
44
import yn from 'yn';
55
import path from 'path';
66
import webpack from 'webpack';
7-
import mapValues from 'lodash/mapValues';
87
import IsoPlugin from 'webpack-isomorphic-tools/plugin';
98
import ExtractTextPlugin from 'extract-text-webpack-plugin';
109
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
1110
import { ReactLoadablePlugin } from 'react-loadable/webpack';
11+
import { mapValues, keyBy } from 'lodash';
1212
import config from '../config';
1313

1414
let ssr = yn(process.env.SSR) || false;
@@ -24,7 +24,9 @@ let plugins = [
2424
extractTextPlugin,
2525
new webpack.ContextReplacementPlugin(/moment[/\\]locale$/, /en|es/),
2626
new webpack.DefinePlugin({
27-
'process.env': config.clientEnv
27+
'process.env': mapValues(keyBy(config.clientEnvVars), (env) => {
28+
return JSON.stringify(process.env[env]);
29+
})
2830
})
2931
];
3032

0 commit comments

Comments
 (0)