Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test verifies that the preload webpack config is used if it is specified by setting the property name on the renderer config and preload config and verifying that the name is as expected on each.

});
});

describe('getRendererConfig', () => {
Expand Down