Record<string, unknown>
{}
Replaces variables in your code with other values or expressions at compile time. This enables different behavior between development and production builds.
Each configuration key represents an identifier or multiple identifiers joined with .
:
typeof
are only defined for typeof calls.For more usage, see Using define and Rspack - DefinePlugin.
export default {
source: {
define: {
PRODUCTION: JSON.stringify(true),
VERSION: JSON.stringify('5fa3b9'),
BROWSER_SUPPORTS_HTML5: true,
TWO: '1 + 1',
'typeof window': JSON.stringify('object'),
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
'import.meta.test': JSON.stringify('foo'),
},
},
};
Expressions are replaced with the corresponding code fragments:
const foo = TWO;
// ⬇️ Turns into
const foo = 1 + 1;