From c6c1f5c05099c8dd5e3779eca2cdca0fa434dcdd Mon Sep 17 00:00:00 2001 From: Jorge Antunes Date: Tue, 1 Aug 2017 11:47:50 +0100 Subject: [PATCH 1/2] make client envs explicit via toolkitSettings --- README.md | 13 ++++++++++++- packages/dev-toolkit/README.md | 13 ++++++++++++- packages/dev-toolkit/src/_userSettings.js | 3 +++ packages/dev-toolkit/src/webpack/config/plugins.js | 9 +++++++-- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6b73591d..56baed55 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ dev-toolkit -v #### Define what modules are bundled into `vendor.js` ```js -// in your package.json, add `toolkitSettings` section +// in your package.json, add `vendor` in `toolkitSettings` section "toolkitSettings": { "vendor": [ "react", @@ -97,6 +97,17 @@ dev-toolkit -v }, ``` +#### Define what environment variables are available on client +```js +// in your package.json, add `sharedEnvs` in `toolkitSettings` section +"toolkitSettings": { + "sharedEnvs": [ + "NODE_ENV", + "API_DOMAIN" + ] +}, +``` + ## Features ##### Compatibility diff --git a/packages/dev-toolkit/README.md b/packages/dev-toolkit/README.md index 88b73f15..8893503b 100644 --- a/packages/dev-toolkit/README.md +++ b/packages/dev-toolkit/README.md @@ -87,7 +87,7 @@ dev-toolkit -v #### Define what modules are bundled into `vendor.js` ```js -// in your package.json, add `toolkitSettings` section +// in your package.json, add `vendor` in `toolkitSettings` section "toolkitSettings": { "vendor": [ "react", @@ -97,6 +97,17 @@ dev-toolkit -v }, ``` +#### Define what environment variables are available on client +```js +// in your package.json, add `sharedEnvs` in `toolkitSettings` section +"toolkitSettings": { + "sharedEnvs": [ + "NODE_ENV", + "API_DOMAIN" + ] +}, +``` + ## Features ##### Compatibility diff --git a/packages/dev-toolkit/src/_userSettings.js b/packages/dev-toolkit/src/_userSettings.js index 1db4d54f..2f18edec 100644 --- a/packages/dev-toolkit/src/_userSettings.js +++ b/packages/dev-toolkit/src/_userSettings.js @@ -25,6 +25,9 @@ export const rootForToolkit = path.resolve(__dirname, '../'); debug('rootForToolkit', rootForToolkit); const pkg = requireOrNull(path.resolve(rootForRequire, 'package.json')) || {}; +export const sharedEnvs = pkg.toolkitSettings && pkg.toolkitSettings.sharedEnvs ? + pkg.toolkitSettings.sharedEnvs : ['NODE_ENV']; +debug('sharedEnvs', sharedEnvs); export const vendor = pkg.toolkitSettings && pkg.toolkitSettings.vendor ? pkg.toolkitSettings.vendor : []; debug('vendor', vendor); diff --git a/packages/dev-toolkit/src/webpack/config/plugins.js b/packages/dev-toolkit/src/webpack/config/plugins.js index 5bae2dc1..edfe3950 100644 --- a/packages/dev-toolkit/src/webpack/config/plugins.js +++ b/packages/dev-toolkit/src/webpack/config/plugins.js @@ -11,12 +11,17 @@ import ManifestRevisionPlugin from 'manifest-revision-webpack-plugin'; import { PATHS, env, + sharedEnvs, currentScript, scriptOptions, namingConvention, buildNamingConvention, } from '../../_userSettings'; +const extractedSharedEnvs = Object.keys(process.env) + .filter(key => sharedEnvs.indexOf(key) !== -1) + .reduce((obj, key) => ({ [key]: process.env[key], ...obj }), {}); + const sharedPlugins = [ new ProgressBarPlugin({ width: 40 }), new webpack.optimize.CommonsChunkPlugin('vendor', `${namingConvention}.js`), @@ -28,9 +33,9 @@ const sharedPlugins = [ ? 'production' : process.env.NODE_ENV ), - // All other environment variables are passed through via `buildSettings` + // All other environment variables are passed through via `buildSettings` if defined in `sharedEnvs` buildSettings: { - env: JSON.stringify(process.env), + env: JSON.stringify(extractedSharedEnvs), }, }), ]; From 3ef10a7534becc98e83af32f486f7e16dc4d0d4b Mon Sep 17 00:00:00 2001 From: Jorge Antunes Date: Tue, 1 Aug 2017 11:49:39 +0100 Subject: [PATCH 2/2] bump version to v5.6.0 --- packages/dev-toolkit/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/dev-toolkit/package.json b/packages/dev-toolkit/package.json index dd04790c..6cba860f 100644 --- a/packages/dev-toolkit/package.json +++ b/packages/dev-toolkit/package.json @@ -1,6 +1,6 @@ { "name": "dev-toolkit", - "version": "5.5.4", + "version": "5.6.0", "description": "Development Toolkit for React Veterans", "main": "index.js", "scripts": {