From f590942465f467c4dc542151f747a5bfb119d899 Mon Sep 17 00:00:00 2001 From: Kyle Ruzic Date: Thu, 3 Feb 2022 13:56:06 -0700 Subject: [PATCH] feat(plugin-webpack): allow specifing a seperate webpack config for your preload (#2679) * feat(plugin-webpack): allow specifing a seperate webpack config for your preload * feat(plugin-webpack): run prettier and lint --- packages/plugin/webpack/src/Config.ts | 5 +++ packages/plugin/webpack/src/WebpackConfig.ts | 2 +- .../plugin/webpack/test/WebpackConfig_spec.ts | 36 +++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) 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', () => {