Skip to content

Commit f3185a2

Browse files
committed
add support for custom webpack config for main process
1 parent 3e107ff commit f3185a2

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,20 +100,23 @@ As per Electron Webpack's documentation, they can be applied:
100100
101101
> in `package.json` at `electronWebpack` or in a separate `electron-webpack.(json|json5|yml)`.
102102
103-
To modify the webpack config for electron builds only, use the webpackConfig object under vue-cli-plugin-electron-builder's plugin options in `vue.config.js`.
103+
To modify the webpack config for the electron render process only, use the webpackConfig object under vue-cli-plugin-electron-builder's plugin options in `vue.config.js`. To modify for the main process, use the webpackMainConfig object.
104104
105-
```
105+
```javascript
106106
// vue.config.js
107107
108-
module.exports = {
108+
module.exports = {
109109
configureWebpack: {
110110
// Non-electron build/serve configuration
111-
// Aliases will be automatically copied from standard config to electron config
111+
// Aliases will be automatically copied from standard config to electron render config
112112
},
113113
pluginOptions: {
114114
electronBuilder: {
115115
webpackConfig: {
116-
// your electron-only webpack config
116+
// your webpack config for electron render process
117+
},
118+
webpackMainConfig: {
119+
// your webpack config for electron main procees
117120
}
118121
}
119122
}

generator/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ module.exports = (api, opts) => {
2020
renderer: {
2121
sourceDirectory: 'src',
2222
webpackConfig: 'dist_electron/webpack.renderer.additions.js'
23+
},
24+
main: {
25+
webpackConfig: 'dist_electron/webpack.main.additions.js'
2326
}
2427
},
2528
build: {

index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,26 @@ function setWebpackOptions (api, options) {
129129
api.resolve('.') + '/dist_electron/webpack.renderer.additions.js',
130130
'module.exports=' + stringConfig
131131
)
132+
if (
133+
options.pluginOptions &&
134+
options.pluginOptions.electronBuilder &&
135+
options.pluginOptions.electronBuilder.webpackMainConfig
136+
) {
137+
let mainConfig = options.pluginOptions.electronBuilder.webpackMainConfig
138+
let stringMainConfig = JSON.stringify(mainConfig, replacer).replace(
139+
/("__REGEXP)(.+?)(")(?=,?)/g,
140+
toRegex
141+
)
142+
fs.writeFileSync(
143+
api.resolve('.') + '/dist_electron/webpack.main.additions.js',
144+
'module.exports=' + stringMainConfig
145+
)
146+
} else {
147+
fs.writeFileSync(
148+
api.resolve('.') + '/dist_electron/webpack.main.additions.js',
149+
'module.exports={}'
150+
)
151+
}
132152
}
133153
module.exports.defaultModes = {
134154
'build:electron': 'production',

0 commit comments

Comments
 (0)