Add CodeValueObject (#42065)

This commit is contained in:
Yenru Chin 2020-02-05 05:55:38 +09:00 committed by GitHub
parent 7cba407dbd
commit 2fa35a8617
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -1665,7 +1665,7 @@ declare namespace webpack {
}
class DefinePlugin extends Plugin {
constructor(definitions: { [key: string]: DefinePlugin.CodeValuePrimitive});
constructor(definitions: {[key: string]: DefinePlugin.CodeValueObject});
static runtimeValue(
fn: ({ module }: { module: compilation.Module }) => DefinePlugin.CodeValuePrimitive,
fileDependencies?: string[]
@ -1681,6 +1681,7 @@ declare namespace webpack {
exec(parser: compilation.normalModuleFactory.Parser): CodeValuePrimitive;
}
type CodeValuePrimitive = string | number | boolean | RegExp | RuntimeValue | null | undefined;
type CodeValueObject = CodeValuePrimitive | {[key: string]: CodeValueObject};
}
class DllPlugin extends Plugin {

View File

@ -446,6 +446,17 @@ plugin = new webpack.DefinePlugin({
BROWSER_SUPPORTS_HTML5: true,
TWO: "1+1",
"typeof window": JSON.stringify("object"),
OBJECT: {
foo: "bar",
bar: {
DEEP_RUNTIME: webpack.DefinePlugin.runtimeValue(
() => JSON.stringify("DEEP_RUUNTIME")
),
foofoo: {
barbar: false
}
}
},
RUNTIME: webpack.DefinePlugin.runtimeValue(
() => JSON.stringify("TEST_VALUE")
)