webpack/test/configCases/plugins/define-plugin/webpack.config.js

65 lines
1.6 KiB
JavaScript
Raw Normal View History

2025-04-22 18:49:30 +08:00
const DefinePlugin = require("../../../../").DefinePlugin;
const Module = require("../../../../").Module;
2025-04-22 18:49:30 +08:00
/** @type {import("../../../../").Configuration} */
module.exports = {
plugins: [
new DefinePlugin({
2015-03-06 05:58:03 +08:00
TRUE: true,
FALSE: false,
NULL: null,
UNDEFINED: undefined,
NUMBER: 100.05,
ZERO: 0,
ONE: 1,
STRING: '"string"',
EMPTY_STRING: '""',
2020-03-09 17:59:31 +08:00
BIGINT: BigInt("9007199254740993"),
ZERO_BIGINT: BigInt(0),
2020-03-02 21:47:04 +08:00
POSITIVE_ZERO: +0,
NEGATIVE_ZER0: -0,
NEGATIVE_NUMBER: -100.25,
POSITIVE_NUMBER: +100.25,
2025-04-22 19:09:25 +08:00
// eslint-disable-next-line object-shorthand
2020-03-29 06:10:15 +08:00
FUNCTION: /* istanbul ignore next */ function (a) {
2017-01-11 17:51:58 +08:00
return a + 1;
},
CODE: "(1+2)",
REGEXP: /abc/i,
OBJECT: {
SUB: {
UNDEFINED: undefined,
2025-04-22 19:09:25 +08:00
// eslint-disable-next-line object-shorthand
2020-03-29 06:10:15 +08:00
FUNCTION: /* istanbul ignore next */ function (a) {
2017-01-11 17:51:58 +08:00
return a + 1;
},
2015-03-06 04:49:22 +08:00
CODE: "(1+2)",
2016-11-10 15:52:00 +08:00
REGEXP: /abc/i,
STRING: JSON.stringify("string")
}
},
ARRAY: [2, [JSON.stringify("six")]],
2016-11-10 15:52:00 +08:00
"process.env.DEFINED_NESTED_KEY": 5,
2018-02-25 18:46:17 +08:00
"process.env.DEFINED_NESTED_KEY_STRING": '"string"',
"typeof wurst": "typeof suppe",
"typeof suppe": "typeof wurst",
2018-02-25 18:46:17 +08:00
wurst: "suppe",
2018-10-31 00:00:45 +08:00
suppe: "wurst",
2018-10-31 00:31:09 +08:00
RUNTIMEVALUE_CALLBACK_ARGUMENT_IS_A_MODULE: DefinePlugin.runtimeValue(
2020-03-29 06:10:15 +08:00
function ({ module }) {
2018-10-31 16:28:42 +08:00
return module instanceof Module;
2018-10-31 00:31:09 +08:00
}
2018-11-05 21:02:00 +08:00
),
A_DOT_J: '"a.j"',
OBJECT2: {
used: 1,
unused: "(() => throw new Error('unused property was rendered'))()",
sub: {
used: 1,
unused: "(() => throw new Error('unused property was rendered'))()"
}
}
})
]
2017-01-11 17:51:58 +08:00
};