Skip to content

Commit 9f0e6c8

Browse files
committed
feat(build/serve): add support for custom render process webpack config
1 parent af3242c commit 9f0e6c8

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

__tests__/commands.spec.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,22 @@ describe('build:electron', () => {
124124
expect(mainConfig.node.test).toBe('expected')
125125
})
126126

127+
test('Custom renderer process webpack config is used if provided', async () => {
128+
await runCommand('build:electron', {
129+
pluginOptions: {
130+
electronBuilder: {
131+
chainWebpackRendererProcess: config => {
132+
config.node.set('test', 'expected')
133+
return config
134+
}
135+
}
136+
}
137+
})
138+
const rendererConfig = buildRenderer.mock.calls[0][3].toConfig()
139+
// Custom node key is passed through
140+
expect(rendererConfig.node.test).toBe('expected')
141+
})
142+
127143
test('Custom main process webpack config is used if provided', async () => {
128144
await runCommand('build:electron', {
129145
pluginOptions: {
@@ -221,6 +237,23 @@ describe('serve:electron', () => {
221237
// Custom node key is passed through
222238
expect(mainConfig.node.test).toBe('expected')
223239
})
240+
241+
test('Custom renderer process webpack config is used if provided', async () => {
242+
await runCommand('serve:electron', {
243+
pluginOptions: {
244+
electronBuilder: {
245+
chainWebpackRendererProcess: config => {
246+
config.node.set('test', 'expected')
247+
return config
248+
}
249+
}
250+
}
251+
})
252+
const rendererConfig = serve.mock.calls[0][3].toConfig()
253+
// Custom node key is passed through
254+
expect(rendererConfig.node.test).toBe('expected')
255+
})
256+
224257
test('If --debug argument is passed, electron is not launched and main process is not minified', async () => {
225258
await runCommand('serve:electron', {}, { debug: true })
226259
const mainConfig = webpack.mock.calls[0][0]

index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ module.exports = (api, options) => {
1919
(usesTypescript ? 'src/background.ts' : 'src/background.js')
2020
const mainProcessChain =
2121
pluginOptions.chainWebpackMainProcess || (config => config)
22+
const rendererProcessChain =
23+
pluginOptions.chainWebpackRendererProcess || (config => config)
2224
api.registerCommand(
2325
'build:electron',
2426
{
@@ -111,7 +113,12 @@ module.exports = (api, options) => {
111113
options.baseUrl = './'
112114
console.log('Bundling render process:')
113115
// Build the render process with the custom args and config
114-
await buildRenderer(vueArgs, api, options, rendererConfig)
116+
await buildRenderer(
117+
vueArgs,
118+
api,
119+
options,
120+
rendererProcessChain(rendererConfig)
121+
)
115122
// Copy fonts to css/fonts. Fixes some issues with static font imports
116123
if (fs.existsSync(api.resolve(outputDir + '/bundled/fonts'))) {
117124
fs.mkdirSync(api.resolve(outputDir + '/bundled/css/fonts'))
@@ -241,7 +248,7 @@ module.exports = (api, options) => {
241248
},
242249
api,
243250
options,
244-
rendererConfig
251+
rendererProcessChain(rendererConfig)
245252
).then(server => {
246253
// Set dev server url
247254
mainConfig

0 commit comments

Comments
 (0)