Skip to content

Commit

Permalink
feat(plugin-webpack): allow specifing a seperate webpack config for y…
Browse files Browse the repository at this point in the history
…our preload (#2679)

* feat(plugin-webpack): allow specifing a seperate webpack config for your preload

* feat(plugin-webpack): run prettier and lint
  • Loading branch information
kyruzic committed Feb 3, 2022
1 parent 2202dcd commit f590942
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/plugin/webpack/src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/webpack/src/WebpackConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export default class WebpackConfigGenerator {
}

async getPreloadRendererConfig(parentPoint: WebpackPluginEntryPoint, entryPoint: WebpackPreloadEntryPoint): Promise<Configuration> {
const rendererConfig = this.resolveConfig(this.pluginConfig.renderer.config);
const rendererConfig = this.resolveConfig(entryPoint.config || this.pluginConfig.renderer.config);
const prefixedEntries = entryPoint.prefixedEntries || [];

return webpackMerge(
Expand Down
36 changes: 36 additions & 0 deletions packages/plugin/webpack/test/WebpackConfig_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit f590942

Please sign in to comment.