@@ -46,9 +46,14 @@ module.exports = (api, options) => {
46
46
// Import the yargs options from electron-builder
47
47
const configureBuildCommand = require ( 'electron-builder/out/builder' )
48
48
. configureBuildCommand
49
- // Prevent mode arg from interfering with electron-builder
50
- const modeIndex = rawArgs . indexOf ( '--mode' )
51
- if ( modeIndex !== - 1 ) rawArgs . splice ( modeIndex , 2 )
49
+ // Prevent custom args from interfering with electron-builder
50
+ const removeArg = ( arg , count ) => {
51
+ const index = rawArgs . indexOf ( arg )
52
+ if ( index !== - 1 ) rawArgs . splice ( index , count )
53
+ }
54
+ removeArg ( '--mode' , 2 )
55
+ removeArg ( '--legacy' , 1 )
56
+ removeArg ( '--skipBundle' , 1 )
52
57
// Parse the raw arguments using electron-builder yargs config
53
58
const builderArgs = yargs
54
59
. command ( [ 'build' , '*' ] , 'Build' , configureBuildCommand )
@@ -67,93 +72,102 @@ module.exports = (api, options) => {
67
72
}
68
73
// User-defined electron-builder config, overwrites/adds to default config
69
74
const userBuildConfig = pluginOptions . builderOptions || { }
70
- // Arguments to be passed to renderer build
71
- const vueArgs = {
72
- _ : [ ] ,
73
- // For the cli-ui webpack dashboard
74
- dashboard : args . dashboard ,
75
- // Make sure files are outputted to proper directory
76
- dest : outputDir + '/bundled' ,
77
- // Enable modern mode
78
- modern : true
79
- }
80
- const mainConfig = new Config ( )
81
- // Configure main process webpack config
82
- mainConfig
83
- . mode ( 'production' )
84
- . target ( 'electron-main' )
85
- . node . set ( '__dirname' , false )
86
- . set ( '__filename' , false )
87
- // Set externals
88
- mainConfig . externals ( getExternals ( api , pluginOptions ) )
89
- mainConfig . output
90
- . path ( api . resolve ( outputDir + '/bundled' ) )
91
- . filename ( 'background.js' )
92
- // Set __static to __dirname (files in public get copied here)
93
- mainConfig
94
- . plugin ( 'define' )
95
- . use ( webpack . DefinePlugin , [ { __static : '__dirname' } ] )
96
- mainConfig . plugin ( 'uglify' ) . use ( UglifyJSPlugin , [
97
- {
98
- parallel : true
75
+ if ( args . skipBundle ) {
76
+ console . log ( 'Not bundling app as --skipBundle was passed' )
77
+ // Build with electron-builder
78
+ buildApp ( )
79
+ } else {
80
+ // Arguments to be passed to renderer build
81
+ const vueArgs = {
82
+ _ : [ ] ,
83
+ // For the cli-ui webpack dashboard
84
+ dashboard : args . dashboard ,
85
+ // Make sure files are outputted to proper directory
86
+ dest : outputDir + '/bundled' ,
87
+ // Enable modern mode unless --legacy is passed
88
+ modern : ! args . legacy
99
89
}
100
- ] )
101
- mainConfig
102
- . plugin ( 'env' )
103
- . use ( webpack . EnvironmentPlugin , [ { NODE_ENV : 'production' } ] )
104
- mainConfig . entry ( 'background' ) . add ( api . resolve ( mainProcessFile ) )
105
- if ( usesTypescript ) {
106
- mainConfig . resolve . extensions . merge ( [ '.js' , '.ts' ] )
107
- mainConfig . module
108
- . rule ( 'ts' )
109
- . test ( / \. t s $ / )
110
- . use ( 'ts-loader' )
111
- . loader ( 'ts-loader' )
112
- . options ( { transpileOnly : ! mainProcessTypeChecking } )
113
- }
114
- // Set the base url so that the app protocol is used
115
- options . baseUrl = './'
116
- console . log ( 'Bundling render process:' )
117
- // Build the render process with the custom args
118
- await api . service . run ( 'build' , vueArgs )
119
- // Copy fonts to css/fonts. Fixes some issues with static font imports
120
- if ( fs . existsSync ( api . resolve ( outputDir + '/bundled/fonts' ) ) ) {
121
- fs . ensureDirSync ( api . resolve ( outputDir + '/bundled/css/fonts' ) )
122
- fs . copySync (
123
- api . resolve ( outputDir + '/bundled/fonts' ) ,
124
- api . resolve ( outputDir + '/bundled/css/fonts' )
125
- )
126
- }
127
- // Build the main process into the renderer process output dir
128
- const bundle = webpack ( mainProcessChain ( mainConfig ) . toConfig ( ) )
129
- console . log ( 'Bundling main process:\n' )
130
- bundle . run ( ( err , stats ) => {
131
- if ( err ) {
132
- console . error ( err . stack || err )
133
- if ( err . details ) {
134
- console . error ( err . details )
90
+ const mainConfig = new Config ( )
91
+ // Configure main process webpack config
92
+ mainConfig
93
+ . mode ( 'production' )
94
+ . target ( 'electron-main' )
95
+ . node . set ( '__dirname' , false )
96
+ . set ( '__filename' , false )
97
+ // Set externals
98
+ mainConfig . externals ( getExternals ( api , pluginOptions ) )
99
+ mainConfig . output
100
+ . path ( api . resolve ( outputDir + '/bundled' ) )
101
+ . filename ( 'background.js' )
102
+ // Set __static to __dirname (files in public get copied here)
103
+ mainConfig
104
+ . plugin ( 'define' )
105
+ . use ( webpack . DefinePlugin , [ { __static : '__dirname' } ] )
106
+ mainConfig . plugin ( 'uglify' ) . use ( UglifyJSPlugin , [
107
+ {
108
+ parallel : true
135
109
}
136
- process . exit ( 1 )
110
+ ] )
111
+ mainConfig
112
+ . plugin ( 'env' )
113
+ . use ( webpack . EnvironmentPlugin , [ { NODE_ENV : 'production' } ] )
114
+ mainConfig . entry ( 'background' ) . add ( api . resolve ( mainProcessFile ) )
115
+ if ( usesTypescript ) {
116
+ mainConfig . resolve . extensions . merge ( [ '.js' , '.ts' ] )
117
+ mainConfig . module
118
+ . rule ( 'ts' )
119
+ . test ( / \. t s $ / )
120
+ . use ( 'ts-loader' )
121
+ . loader ( 'ts-loader' )
122
+ . options ( { transpileOnly : ! mainProcessTypeChecking } )
123
+ }
124
+ // Set the base url so that the app protocol is used
125
+ options . baseUrl = './'
126
+ console . log ( 'Bundling render process:' )
127
+ // Build the render process with the custom args
128
+ await api . service . run ( 'build' , vueArgs )
129
+ // Copy fonts to css/fonts. Fixes some issues with static font imports
130
+ if ( fs . existsSync ( api . resolve ( outputDir + '/bundled/fonts' ) ) ) {
131
+ fs . ensureDirSync ( api . resolve ( outputDir + '/bundled/css/fonts' ) )
132
+ fs . copySync (
133
+ api . resolve ( outputDir + '/bundled/fonts' ) ,
134
+ api . resolve ( outputDir + '/bundled/css/fonts' )
135
+ )
137
136
}
137
+ // Build the main process into the renderer process output dir
138
+ const bundle = webpack ( mainProcessChain ( mainConfig ) . toConfig ( ) )
139
+ console . log ( 'Bundling main process:\n' )
140
+ bundle . run ( ( err , stats ) => {
141
+ if ( err ) {
142
+ console . error ( err . stack || err )
143
+ if ( err . details ) {
144
+ console . error ( err . details )
145
+ }
146
+ process . exit ( 1 )
147
+ }
138
148
139
- const info = stats . toJson ( )
149
+ const info = stats . toJson ( )
140
150
141
- if ( stats . hasErrors ( ) ) {
142
- console . error ( info . errors )
143
- process . exit ( 1 )
144
- }
151
+ if ( stats . hasErrors ( ) ) {
152
+ console . error ( info . errors )
153
+ process . exit ( 1 )
154
+ }
145
155
146
- if ( stats . hasWarnings ( ) ) {
147
- console . warn ( info . warnings )
148
- }
156
+ if ( stats . hasWarnings ( ) ) {
157
+ console . warn ( info . warnings )
158
+ }
149
159
150
- console . log (
151
- stats . toString ( {
152
- chunks : false ,
153
- colors : true
154
- } )
155
- )
160
+ console . log (
161
+ stats . toString ( {
162
+ chunks : false ,
163
+ colors : true
164
+ } )
165
+ )
156
166
167
+ buildApp ( )
168
+ } )
169
+ }
170
+ function buildApp ( ) {
157
171
console . log ( '\nBuilding app with electron-builder:\n' )
158
172
// Build the app using electron builder
159
173
builder
@@ -174,7 +188,7 @@ module.exports = (api, options) => {
174
188
// handle error
175
189
throw err
176
190
} )
177
- } )
191
+ }
178
192
}
179
193
)
180
194
api . registerCommand (
0 commit comments