Skip to content

Commit 167e5c6

Browse files
committed
Merge pull request webpack#107 from jhnns/fix-undefined-define-option
Allow define-variables to be undefined
2 parents 5dd2e0b + 55e073c commit 167e5c6

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

‎lib/DefinePlugin.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ DefinePlugin.prototype.apply = function(compiler) {
1313
(function walkDefinitions(definitions, prefix) {
1414
Object.keys(definitions).forEach(function(key) {
1515
var code = definitions[key];
16-
if(typeof code === "object") {
16+
if(code === undefined || code === null) code = code + "";
17+
else if(typeof code === "object") {
1718
walkDefinitions(code, key + ".");
1819
applyObjectDefine(key, code);
1920
return;
2021
}
21-
if(typeof code !== "string" && code.toString) code = code.toString();
22-
else if(typeof code !== "string") code = code + "";
22+
else code = code.toString();
2323
applyDefine(prefix + key, code);
2424
});
2525
}(this.definitions, ""));

‎test/browsertest/library2config.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ module.exports = {
88
]
99
},
1010
optimize: {
11-
maxChunks: 2,
11+
maxChunks: 2
1212
},
1313
define: {
14+
CONST_UNDEFINED: undefined,
15+
CONST_NULL: null,
1416
CONST_TRUE: true,
1517
CONST_FALSE: false,
1618
CONST_FUNCTION: function() { return "ok"; },

‎test/browsertest/node_modules/library2/lib/main.js‎

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)