Skip to content

Commit

Permalink
Merge pull request #42 from stoikerty/feature/make-client-envs-explicit
Browse files Browse the repository at this point in the history
make client envs explicit via toolkitSettings
  • Loading branch information
stoikerty authored Aug 1, 2017
2 parents 7ce4dd7 + 3ef10a7 commit c8f1e72
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
Expand Down
13 changes: 12 additions & 1 deletion packages/dev-toolkit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/dev-toolkit/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
3 changes: 3 additions & 0 deletions packages/dev-toolkit/src/_userSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 7 additions & 2 deletions packages/dev-toolkit/src/webpack/config/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`),
Expand All @@ -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),
},
}),
];
Expand Down

0 comments on commit c8f1e72

Please sign in to comment.