Skip to content

Commit

Permalink
Use process.env as a proper object. (#565)
Browse files Browse the repository at this point in the history
Earlier it's not possible to log process.env from the console.
It's only individual keys like procss.env.NODE_ENV.
  • Loading branch information
arunoda authored Oct 24, 2016
1 parent 3f30f0c commit 0e02ced
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
Empty file modified dist/server/build.js
100644 → 100755
Empty file.
18 changes: 10 additions & 8 deletions dist/server/config/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ Object.defineProperty(exports, "__esModule", {
});
exports.nodePaths = exports.nodeModulesPaths = exports.excludePaths = exports.includePaths = exports.OccurenceOrderPlugin = undefined;

var _keys = require('babel-runtime/core-js/object/keys');

var _keys2 = _interopRequireDefault(_keys);

var _stringify = require('babel-runtime/core-js/json/stringify');

var _stringify2 = _interopRequireDefault(_stringify);

var _keys = require('babel-runtime/core-js/object/keys');

var _keys2 = _interopRequireDefault(_keys);

exports.loadEnv = loadEnv;

var _webpack = require('webpack');
Expand Down Expand Up @@ -47,20 +47,22 @@ function loadEnv() {

var defaultNodeEnv = options.production ? 'production' : 'development';
var env = {
'process.env.NODE_ENV': (0, _stringify2.default)(process.env.NODE_ENV || defaultNodeEnv),
'NODE_ENV': process.env.NODE_ENV || defaultNodeEnv,
// This is to support CRA's public folder feature.
// In production we set this to dot(.) to allow the browser to access these assests
// even when deployed inside a subpath. (like in GitHub pages)
// In development this is just empty as we always serves from the root.
'process.env.PUBLIC_URL': (0, _stringify2.default)(options.production ? '.' : '')
'PUBLIC_URL': options.production ? '.' : ''
};

(0, _keys2.default)(process.env).filter(function (name) {
return (/^STORYBOOK_/.test(name)
);
}).forEach(function (name) {
env['process.env.' + name] = (0, _stringify2.default)(process.env[name]);
env[name] = process.env[name];
});

return env;
return {
'process.env': (0, _stringify2.default)(env)
};
}
10 changes: 6 additions & 4 deletions src/server/config/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,21 @@ export const nodePaths = (process.env.NODE_PATH || '')
export function loadEnv(options = {}) {
const defaultNodeEnv = options.production ? 'production' : 'development';
const env = {
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || defaultNodeEnv),
'NODE_ENV': process.env.NODE_ENV || defaultNodeEnv,
// This is to support CRA's public folder feature.
// In production we set this to dot(.) to allow the browser to access these assests
// even when deployed inside a subpath. (like in GitHub pages)
// In development this is just empty as we always serves from the root.
'process.env.PUBLIC_URL': JSON.stringify(options.production ? '.' : ''),
'PUBLIC_URL': options.production ? '.' : '',
};

Object.keys(process.env)
.filter(name => /^STORYBOOK_/.test(name))
.forEach((name) => {
env[`process.env.${name}`] = JSON.stringify(process.env[name]);
env[name] = process.env[name];
});

return env;
return {
'process.env': JSON.stringify(env),
};
}

0 comments on commit 0e02ced

Please # to comment.