Skip to content

Commit 2491f5d

Browse files
authored
Merge pull request webpack#7471 from webpack/fix/7470
Add a test case about nodeEnv
2 parents 310cf6c + 0743250 commit 2491f5d

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

lib/WebpackOptionsDefaulter.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,10 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
294294
}
295295
}
296296
]);
297-
this.set(
298-
"optimization.nodeEnv",
299-
"make",
300-
options => options.mode || "production"
301-
);
297+
this.set("optimization.nodeEnv", "make", options => {
298+
// TODO: In webpack 5, it should return `false` when mode is `none`
299+
return options.mode || "production";
300+
});
302301

303302
this.set("resolve", "call", value => Object.assign({}, value));
304303
this.set("resolve.unsafeCache", true);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
it("should set NODE_ENV according to mode", () => {
2+
expect(process.env.NODE_ENV).toBe(__MODE__);
3+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"use strict";
2+
3+
const DefinePlugin = require("../../../../lib/DefinePlugin");
4+
5+
module.exports = [
6+
{
7+
name: "development",
8+
mode: "development",
9+
plugins: [new DefinePlugin({ __MODE__: `"development"` })]
10+
},
11+
{
12+
name: "production",
13+
mode: "production",
14+
plugins: [new DefinePlugin({ __MODE__: `"production"` })]
15+
},
16+
{
17+
name: "none",
18+
mode: "none",
19+
plugins: [new DefinePlugin({ __MODE__: `"none"` })]
20+
}
21+
];

0 commit comments

Comments
 (0)