diff --git a/packages/plugin/webpack/src/Config.ts b/packages/plugin/webpack/src/Config.ts index 4af7e45a1d..faf2cf6868 100644 --- a/packages/plugin/webpack/src/Config.ts +++ b/packages/plugin/webpack/src/Config.ts @@ -45,6 +45,11 @@ export interface WebpackPreloadEntryPoint { * entry files into your application. */ prefixedEntries?: string[]; + /** + * The optional webpack config for your preload process, defaults to the + * renderer webpack config if blank + */ + config?: WebpackConfiguration | string; } export interface WebpackPluginRendererConfig { diff --git a/packages/plugin/webpack/src/WebpackConfig.ts b/packages/plugin/webpack/src/WebpackConfig.ts index 6b40253844..479a7bbda8 100644 --- a/packages/plugin/webpack/src/WebpackConfig.ts +++ b/packages/plugin/webpack/src/WebpackConfig.ts @@ -142,7 +142,7 @@ export default class WebpackConfigGenerator { } async getPreloadRendererConfig(parentPoint: WebpackPluginEntryPoint, entryPoint: WebpackPreloadEntryPoint): Promise { - const rendererConfig = this.resolveConfig(this.pluginConfig.renderer.config); + const rendererConfig = this.resolveConfig(entryPoint.config || this.pluginConfig.renderer.config); const prefixedEntries = entryPoint.prefixedEntries || []; return webpackMerge( diff --git a/packages/plugin/webpack/test/WebpackConfig_spec.ts b/packages/plugin/webpack/test/WebpackConfig_spec.ts index 59b6c6254e..720fef608a 100644 --- a/packages/plugin/webpack/test/WebpackConfig_spec.ts +++ b/packages/plugin/webpack/test/WebpackConfig_spec.ts @@ -332,6 +332,42 @@ describe('WebpackConfigGenerator', () => { ); expect(webpackConfig.target).to.equal('electron-preload'); }); + + it('allows you to specify a preload webpack config', async () => { + const config = { + renderer: { + config: { + name: 'renderer', + target: 'web', + entry: 'renderer', + }, + entryPoints: [ + { + name: 'main', + preload: { + js: 'preload.js', + config: { + name: 'preload', + target: 'electron-preload', + entry: 'preload', + }, + }, + }, + ], + }, + } as WebpackPluginConfig; + const generator = new WebpackConfigGenerator(config, mockProjectDir, true, 3000); + const entryPoint = config.renderer.entryPoints[0]; + const preloadWebpackConfig = await generator.getPreloadRendererConfig( + entryPoint, + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + entryPoint.preload! + ); + const rendererWebpackConfig = await generator.getRendererConfig(config.renderer.entryPoints); + // Our preload config plugins is an empty list while our renderer config plugins has a member + expect(preloadWebpackConfig.name).to.equal('preload'); + expect(rendererWebpackConfig.name).to.equal('renderer'); + }); }); describe('getRendererConfig', () => {