@@ -37,11 +37,20 @@ module.exports = (api, options) => {
37
37
// Import the yargs options from electron-builder
38
38
const configureBuildCommand = require ( 'electron-builder/out/builder' )
39
39
. configureBuildCommand
40
- // Parse the raw arguments using electron-builder yargs config
40
+ // Parse the raw arguments using electron-builder yargs config
41
41
const builderArgs = yargs
42
42
. command ( [ 'build' , '*' ] , 'Build' , configureBuildCommand )
43
43
. parse ( rawArgs )
44
44
const rendererConfig = api . resolveChainableWebpackConfig ( )
45
+ // Configure base webpack config to work properly with electron
46
+ rendererConfig . target ( 'electron-renderer' ) . output . publicPath ( './' )
47
+ rendererConfig . node . set ( '__dirname' , false ) . set ( '__filename' , false )
48
+ // Set process.env.BASE_URL and __static to absolute file path
49
+ rendererConfig . plugin ( 'define' ) . tap ( args => {
50
+ args [ 0 ] [ 'process.env' ] . BASE_URL = '__dirname'
51
+ args [ 0 ] . __static = '__dirname'
52
+ return args
53
+ } )
45
54
// Base config used in electron-builder build
46
55
const defaultBuildConfig = {
47
56
directories : {
@@ -74,6 +83,10 @@ module.exports = (api, options) => {
74
83
mainConfig . output
75
84
. path ( api . resolve ( outputDir + '/bundled' ) )
76
85
. filename ( 'background.js' )
86
+ // Set __static to __dirname (files in public get copied here)
87
+ mainConfig
88
+ . plugin ( 'define' )
89
+ . use ( webpack . DefinePlugin , [ { __static : '__dirname' } ] )
77
90
mainConfig . plugin ( 'uglify' ) . use ( UglifyJSPlugin , [
78
91
{
79
92
parallel : true
@@ -94,9 +107,6 @@ module.exports = (api, options) => {
94
107
}
95
108
96
109
console . log ( 'Bundling render process:' )
97
- // Configure base webpack config to work properly with electron
98
- rendererConfig . target ( 'electron-renderer' ) . output . publicPath ( './' )
99
- rendererConfig . node . set ( '__dirname' , false ) . set ( '__filename' , false )
100
110
// Build the render process with the custom args and config
101
111
await buildRenderer ( vueArgs , api , options , rendererConfig )
102
112
// Copy fonts to css/fonts. Fixes some issues with static font imports
@@ -176,6 +186,11 @@ module.exports = (api, options) => {
176
186
. target ( 'electron-renderer' )
177
187
. node . set ( '__dirname' , false )
178
188
. set ( '__filename' , false )
189
+ // Set __static to absolute path to public folder
190
+ rendererConfig . plugin ( 'define' ) . tap ( args => {
191
+ args [ 0 ] . __static = JSON . stringify ( api . resolve ( './public' ) )
192
+ return args
193
+ } )
179
194
// Configure webpack for main process
180
195
const mainConfig = new Config ( )
181
196
mainConfig
@@ -189,6 +204,12 @@ module.exports = (api, options) => {
189
204
parallel : true
190
205
}
191
206
] )
207
+ // Set __static to absolute path to public folder
208
+ mainConfig . plugin ( 'define' ) . use ( webpack . DefinePlugin , [
209
+ {
210
+ __static : JSON . stringify ( api . resolve ( './public' ) )
211
+ }
212
+ ] )
192
213
mainConfig
193
214
. plugin ( 'env' )
194
215
. use ( webpack . EnvironmentPlugin , [ { NODE_ENV : 'development' } ] )
0 commit comments