@@ -3,6 +3,17 @@ const webpack = require('webpack')
3
3
const Config = require ( 'webpack-chain' )
4
4
const merge = require ( 'lodash.merge' )
5
5
const fs = require ( 'fs-extra' )
6
+ const path = require ( 'path' )
7
+ const {
8
+ log,
9
+ done,
10
+ info,
11
+ logWithSpinner,
12
+ stopSpinner,
13
+ warn,
14
+ error
15
+ } = require ( '@vue/cli-shared-utils' )
16
+ const formatStats = require ( '@vue/cli-service/lib/commands/build/formatStats' )
6
17
const { chainWebpack, getExternals } = require ( './lib/webpackConfig' )
7
18
8
19
module . exports = ( api , options ) => {
@@ -92,7 +103,7 @@ module.exports = (api, options) => {
92
103
}
93
104
// Set the base url so that the app protocol is used
94
105
options . baseUrl = './'
95
- console . log ( 'Bundling render process:' )
106
+ info ( 'Bundling render process:' )
96
107
// Build the render process with the custom args
97
108
await api . service . run ( 'build' , vueArgs )
98
109
// Copy package.json to output dir
@@ -123,37 +134,26 @@ module.exports = (api, options) => {
123
134
mainProcessChain,
124
135
usesTypescript
125
136
} )
126
- console . log ( 'Bundling main process:\n ' )
137
+ logWithSpinner ( 'Bundling main process... ' )
127
138
bundle . run ( ( err , stats ) => {
139
+ stopSpinner ( false )
128
140
if ( err ) {
129
- console . error ( err . stack || err )
130
- if ( err . details ) {
131
- console . error ( err . details )
132
- }
133
141
return reject ( err )
134
142
}
135
-
136
- const info = stats . toJson ( )
137
-
138
143
if ( stats . hasErrors ( ) ) {
139
- return reject ( info . errors )
144
+ // eslint-disable-next-line prefer-promise-reject-errors
145
+ return reject ( `Build failed with errors.` )
140
146
}
141
-
142
- if ( stats . hasWarnings ( ) ) {
143
- console . warn ( info . warnings )
144
- }
145
-
146
- console . log (
147
- stats . toString ( {
148
- chunks : false ,
149
- colors : true
150
- } )
147
+ const targetDirShort = path . relative (
148
+ api . service . context ,
149
+ `${ outputDir } /bundled`
151
150
)
151
+ log ( formatStats ( stats , targetDirShort , api ) )
152
152
153
153
buildApp ( )
154
154
} )
155
155
} else {
156
- console . log (
156
+ info (
157
157
'Not bundling main process as bundleMainProcess was set to false in plugin options'
158
158
)
159
159
// Copy main process file instead of bundling it
@@ -165,7 +165,7 @@ module.exports = (api, options) => {
165
165
}
166
166
}
167
167
function buildApp ( ) {
168
- console . log ( '\nBuilding app with electron-builder:\n ')
168
+ info ( 'Building app with electron-builder:')
169
169
// Build the app using electron builder
170
170
builder
171
171
. build ( {
@@ -179,7 +179,7 @@ module.exports = (api, options) => {
179
179
} )
180
180
. then ( ( ) => {
181
181
// handle result
182
- console . log ( '\nBuild complete!\n ')
182
+ done ( 'Build complete!')
183
183
resolve ( )
184
184
} )
185
185
. catch ( err => {
@@ -206,7 +206,6 @@ module.exports = (api, options) => {
206
206
]
207
207
const mainProcessArgs = pluginOptions . mainProcessArgs || [ ]
208
208
209
- console . log ( '\nStarting development server:\n' )
210
209
// Run the serve command
211
210
const server = await api . service . run ( 'serve' , {
212
211
_ : [ ] ,
@@ -241,37 +240,22 @@ module.exports = (api, options) => {
241
240
usesTypescript,
242
241
server
243
242
} )
244
- console . log ( 'Bundling main process:\n ' )
243
+ logWithSpinner ( 'Bundling main process... ' )
245
244
bundle . run ( ( err , stats ) => {
245
+ stopSpinner ( false )
246
246
if ( err ) {
247
- console . error ( err . stack || err )
248
- if ( err . details ) {
249
- console . error ( err . details )
250
- }
251
- process . exit ( 1 )
247
+ throw err
252
248
}
253
-
254
- const info = stats . toJson ( )
255
-
256
249
if ( stats . hasErrors ( ) ) {
257
- console . error ( info . errors )
250
+ error ( `Build failed with errors.` )
258
251
process . exit ( 1 )
259
252
}
260
-
261
- if ( stats . hasWarnings ( ) ) {
262
- console . warn ( info . warnings )
263
- }
264
-
265
- console . log (
266
- stats . toString ( {
267
- chunks : false ,
268
- colors : true
269
- } )
270
- )
253
+ const targetDirShort = path . relative ( api . service . context , outputDir )
254
+ log ( formatStats ( stats , targetDirShort , api ) )
271
255
launchElectron ( )
272
256
} )
273
257
} else {
274
- console . log (
258
+ info (
275
259
'Not bundling main process as bundleMainProcess was set to false in plugin options'
276
260
)
277
261
// Copy main process file instead of bundling it
@@ -291,14 +275,16 @@ module.exports = (api, options) => {
291
275
292
276
function launchElectron ( ) {
293
277
if ( args . debug ) {
278
+ console . log ( info )
279
+
294
280
// Do not launch electron and provide instructions on launching through debugger
295
- console . log (
296
- '\nNot launching electron as debug argument was passed. You must launch electron though your debugger.'
281
+ info (
282
+ 'Not launching electron as debug argument was passed. You must launch electron though your debugger.'
297
283
)
298
- console . log (
284
+ info (
299
285
`If you are using Spectron, make sure to set the IS_TEST env variable to true.`
300
286
)
301
- console . log (
287
+ info (
302
288
'Learn more about debugging the main process at https://nklayman.github.io/vue-cli-plugin-electron-builder/guide/testingAndDebugging.html#debugging.'
303
289
)
304
290
} else if ( args . headless ) {
@@ -307,14 +293,14 @@ module.exports = (api, options) => {
307
293
console . log ( `$WEBPACK_DEV_SERVER_URL=${ server . url } ` )
308
294
} else {
309
295
// Launch electron with execa
310
- if ( mainProcessArgs ) {
311
- console . log (
312
- '\nLaunching Electron with arguments: ' +
296
+ if ( mainProcessArgs . length > 0 ) {
297
+ info (
298
+ 'Launching Electron with arguments: " ' +
313
299
mainProcessArgs . join ( ' ' ) +
314
- ' ...'
300
+ '" ...'
315
301
)
316
302
} else {
317
- console . log ( '\nLaunching Electron...')
303
+ info ( 'Launching Electron...')
318
304
}
319
305
child = execa (
320
306
require ( 'electron' ) ,
@@ -369,9 +355,7 @@ module.exports = (api, options) => {
369
355
`See https://nklayman.github.io/vue-cli-plugin-electron-builder/ for more details about this plugin.`
370
356
} ,
371
357
( args , rawArgs ) => {
372
- console . log (
373
- 'This command is deprecated. Please use electron:build instead.'
374
- )
358
+ warn ( 'This command is deprecated. Please use electron:build instead.' )
375
359
return api . service . run (
376
360
'electron:build' ,
377
361
{ ...args , _ : [ 'First arg is removed' , ...args . _ ] } ,
@@ -389,9 +373,7 @@ module.exports = (api, options) => {
389
373
details : `See https://nklayman.github.io/vue-cli-plugin-electron-builder/ for more details about this plugin.`
390
374
} ,
391
375
( args , rawArgs ) => {
392
- console . log (
393
- 'This command is deprecated. Please use electron:serve instead.'
394
- )
376
+ warn ( 'This command is deprecated. Please use electron:serve instead.' )
395
377
return api . service . run (
396
378
'electron:serve' ,
397
379
{ ...args , _ : [ 'First arg is removed' , ...args . _ ] } ,
@@ -468,6 +450,18 @@ function bundleMain ({
468
450
config
469
451
. entry ( isBuild ? 'background' : 'index' )
470
452
. add ( api . resolve ( mainProcessFile ) )
453
+ const {
454
+ transformer,
455
+ formatter
456
+ } = require ( '@vue/cli-service/lib/util/resolveLoaderError' )
457
+ config
458
+ . plugin ( 'friendly-errors' )
459
+ . use ( require ( 'friendly-errors-webpack-plugin' ) , [
460
+ {
461
+ additionalTransformers : [ transformer ] ,
462
+ additionalFormatters : [ formatter ]
463
+ }
464
+ ] )
471
465
if ( usesTypescript ) {
472
466
config . resolve . extensions . merge ( [ '.js' , '.ts' ] )
473
467
config . module
0 commit comments