diff --git a/declarations/WebpackOptions.d.ts b/declarations/WebpackOptions.d.ts index 7e45ddbd437..d2408e18456 100644 --- a/declarations/WebpackOptions.d.ts +++ b/declarations/WebpackOptions.d.ts @@ -390,7 +390,8 @@ export interface WebpackOptions { | "async-node" | "node-webkit" | "electron-main" - | "electron-renderer") + | "electron-renderer" + | "electron-preload") | ((compiler: import("../lib/Compiler")) => void); /** * Enter watch mode, which rebuilds on file change. diff --git a/lib/WebpackOptionsApply.js b/lib/WebpackOptionsApply.js index ff4601cee16..32a813e42b0 100644 --- a/lib/WebpackOptionsApply.js +++ b/lib/WebpackOptionsApply.js @@ -156,11 +156,19 @@ class WebpackOptionsApply extends OptionsApply { new LoaderTargetPlugin(options.target).apply(compiler); break; case "electron-renderer": - JsonpTemplatePlugin = require("./web/JsonpTemplatePlugin"); + case "electron-preload": FetchCompileWasmTemplatePlugin = require("./web/FetchCompileWasmTemplatePlugin"); NodeTargetPlugin = require("./node/NodeTargetPlugin"); ExternalsPlugin = require("./ExternalsPlugin"); - new JsonpTemplatePlugin().apply(compiler); + if (options.target === "electron-renderer") { + JsonpTemplatePlugin = require("./web/JsonpTemplatePlugin"); + new JsonpTemplatePlugin().apply(compiler); + } else if (options.target === "electron-preload") { + NodeTemplatePlugin = require("./node/NodeTemplatePlugin"); + new NodeTemplatePlugin({ + asyncChunkLoading: true + }).apply(compiler); + } new FetchCompileWasmTemplatePlugin({ mangleImports: options.optimization.mangleWasmImports }).apply(compiler); diff --git a/schemas/WebpackOptions.json b/schemas/WebpackOptions.json index 53e0948f437..5e51cddeb3a 100644 --- a/schemas/WebpackOptions.json +++ b/schemas/WebpackOptions.json @@ -2128,7 +2128,8 @@ "async-node", "node-webkit", "electron-main", - "electron-renderer" + "electron-renderer", + "electron-preload" ] }, {