Skip to content

Commit

Permalink
Merge pull request #1042 from stealjs/node-env
Browse files Browse the repository at this point in the history
Make "production" the default NODE_ENV.
  • Loading branch information
matthewp committed Jul 19, 2018
2 parents 115b92a + d501169 commit bd0f96e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
9 changes: 6 additions & 3 deletions lib/graph/envify.js
Expand Up @@ -3,18 +3,21 @@ var transformActiveSource = require("../node/transform_active_source");

module.exports = function(graph, options) {
options = options || {};
var env = Object.assign({
NODE_ENV: "production"
}, process.env);

if (Array.isArray(graph)) {
graph.forEach(envifyNode);
} else {
Object.keys(graph).forEach(function eachKey(name) {
envifyNode(graph[name]);
envifyNode(graph[name], env);
});
}
return graph;
};

function envifyNode(node) {
function envifyNode(node, env) {
transformActiveSource(node, "envify-true", function transformNode(
node,
source
Expand All @@ -23,7 +26,7 @@ function envifyNode(node) {

// only replace Node-style environment variables from JS code
if (isJsNode) {
source.code = envify(source.code, [process.env]);
source.code = envify(source.code, [env]);
}

return source;
Expand Down
5 changes: 3 additions & 2 deletions lib/stream/add_loader_shim.js
Expand Up @@ -6,6 +6,7 @@ var assign = require("lodash/assign");
var clone = require("lodash/cloneDeep");
var defaultTo = require("lodash/defaultTo");
var isPluginExcludedFromBuild = require("../node/is_plugin_excluded");
var winston = require("winston");

module.exports = function() {
return through.obj(function(data, enc, next) {
Expand All @@ -25,9 +26,9 @@ module.exports = function() {
*/
function addAtLoaderShim(data) {
if (includesAtLoader(omit(data.graph, data.loader.configMain))) {
console.log(
winston.warn(
colors.yellow(
`Warning: the @loader module is not fully supported in optimized builds`
`the @loader module is not fully supported in optimized builds`
)
);

Expand Down
5 changes: 3 additions & 2 deletions lib/stream/add_steal_shim.js
Expand Up @@ -4,6 +4,7 @@ var keys = require("lodash/keys");
var omit = require("lodash/omit");
var defaultTo = require("lodash/defaultTo");
var isPluginExcludedFromBuild = require("../node/is_plugin_excluded");
var winston = require("winston");

module.exports = function() {
return through.obj(function(data, enc, next) {
Expand All @@ -24,9 +25,9 @@ function addAtLoaderShim(data) {
var graph = omit(data.graph, data.loader.configMain);

if (includesAtSteal(graph)) {
console.log(
winston.warn(
colors.yellow(
`Warning: the @steal module is not fully supported in optimized builds`
`the @steal module is not fully supported in optimized builds`
)
);
data.graph["@steal"] = makeShimNode(data.loader.main);
Expand Down
6 changes: 5 additions & 1 deletion test/slim/basics/main.js
@@ -1,3 +1,7 @@
var foo = require("./foo");

window.foo = foo;
if (process.env.NODE_ENV !== "production") {
console.log("hello world");
}

window.foo = foo;

0 comments on commit bd0f96e

Please sign in to comment.