From d50116914894ce9e610af3387d7bd5b2a37a2e09 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Thu, 19 Jul 2018 12:39:16 -0400 Subject: [PATCH] Make "production" the default NODE_ENV. This fixes #1041 --- lib/graph/envify.js | 9 ++++++--- lib/stream/add_loader_shim.js | 5 +++-- lib/stream/add_steal_shim.js | 5 +++-- test/slim/basics/main.js | 6 +++++- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/graph/envify.js b/lib/graph/envify.js index 8f885020..889f2b24 100644 --- a/lib/graph/envify.js +++ b/lib/graph/envify.js @@ -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 @@ -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; diff --git a/lib/stream/add_loader_shim.js b/lib/stream/add_loader_shim.js index fbc0f2c2..3acc01eb 100644 --- a/lib/stream/add_loader_shim.js +++ b/lib/stream/add_loader_shim.js @@ -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) { @@ -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` ) ); diff --git a/lib/stream/add_steal_shim.js b/lib/stream/add_steal_shim.js index c7b18883..17989059 100644 --- a/lib/stream/add_steal_shim.js +++ b/lib/stream/add_steal_shim.js @@ -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) { @@ -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); diff --git a/test/slim/basics/main.js b/test/slim/basics/main.js index 67b45403..4a5e9ec6 100644 --- a/test/slim/basics/main.js +++ b/test/slim/basics/main.js @@ -1,3 +1,7 @@ var foo = require("./foo"); -window.foo = foo; \ No newline at end of file +if (process.env.NODE_ENV !== "production") { + console.log("hello world"); +} + +window.foo = foo;