1
- const UglifyJSPlugin = require ( 'uglifyjs-webpack-plugin' ) ;
2
- const webpack = require ( 'webpack' ) ;
3
- const Config = require ( 'webpack-chain' ) ;
1
+ const UglifyJSPlugin = require ( 'uglifyjs-webpack-plugin' )
2
+ const webpack = require ( 'webpack' )
3
+ const Config = require ( 'webpack-chain' )
4
4
module . exports = ( api , options ) => {
5
5
api . registerCommand (
6
6
'build:electron' ,
@@ -15,87 +15,87 @@ module.exports = (api, options) => {
15
15
} ,
16
16
async ( ) => {
17
17
const buildRenderer = require ( '@vue/cli-service/lib/commands/build' )
18
- . build ;
19
- const fs = require ( 'fs-extra' ) ;
20
- const builder = require ( 'electron-builder' ) ;
21
- const rendererConfig = api . resolveChainableWebpackConfig ( ) ;
18
+ . build
19
+ const fs = require ( 'fs-extra' )
20
+ const builder = require ( 'electron-builder' )
21
+ const rendererConfig = api . resolveChainableWebpackConfig ( )
22
22
const defaultBuildConfig = {
23
23
directories : {
24
24
output : 'dist_electron'
25
25
} ,
26
26
files : [ 'dist/**/*' , 'node_modules/**/*' , 'package.json' ] ,
27
27
extends : null
28
- } ;
29
- const userBuildConfig = ( function ( ) {
28
+ }
29
+ const userBuildConfig = ( function ( ) {
30
30
if (
31
31
options . pluginOptions &&
32
32
options . pluginOptions . electronBuilder &&
33
33
options . pluginOptions . electronBuilder . builderConfig
34
34
) {
35
- return options . pluginOptions . electronBuilder . builderConfig ;
35
+ return options . pluginOptions . electronBuilder . builderConfig
36
36
} else {
37
- return { } ;
37
+ return { }
38
38
}
39
- } ) ( ) ;
40
- const mainConfig = new Config ( ) ;
39
+ } ) ( )
40
+ const mainConfig = new Config ( )
41
41
mainConfig
42
42
. mode ( 'production' )
43
43
. devtool ( 'source-map' )
44
44
. target ( 'electron-main' )
45
45
. node . set ( '__dirname' , false )
46
- . set ( '__filename' , false ) ;
47
- mainConfig . output . path ( api . resolve ( './dist' ) ) . filename ( 'background.js' ) ;
46
+ . set ( '__filename' , false )
47
+ mainConfig . output . path ( api . resolve ( './dist' ) ) . filename ( 'background.js' )
48
48
mainConfig . plugin ( 'uglify' ) . use ( UglifyJSPlugin , [
49
49
{
50
50
parallel : true ,
51
51
sourceMap : true
52
52
}
53
- ] ) ;
53
+ ] )
54
54
mainConfig
55
55
. plugin ( 'env' )
56
- . use ( webpack . EnvironmentPlugin , [ { NODE_ENV : 'production' } ] ) ;
57
- mainConfig . entry ( 'background' ) . add ( api . resolve ( './src/background.js' ) ) ;
56
+ . use ( webpack . EnvironmentPlugin , [ { NODE_ENV : 'production' } ] )
57
+ mainConfig . entry ( 'background' ) . add ( api . resolve ( './src/background.js' ) )
58
58
59
- console . log ( 'Bundling render process:' ) ;
60
- rendererConfig . target ( 'electron-renderer' ) . output . publicPath ( './' ) ;
61
- await buildRenderer ( { _ : [ ] } , api , options , rendererConfig ) ;
59
+ console . log ( 'Bundling render process:' )
60
+ rendererConfig . target ( 'electron-renderer' ) . output . publicPath ( './' )
61
+ await buildRenderer ( { _ : [ ] } , api , options , rendererConfig )
62
62
if ( fs . existsSync ( api . resolve ( './dist/fonts' ) ) ) {
63
- fs . mkdirSync ( api . resolve ( './dist/css/fonts' ) ) ;
63
+ fs . mkdirSync ( api . resolve ( './dist/css/fonts' ) )
64
64
fs . copySync (
65
65
api . resolve ( './dist/fonts' ) ,
66
66
api . resolve ( './dist/css/fonts' )
67
- ) ;
67
+ )
68
68
}
69
- const bundle = webpack ( mainConfig . toConfig ( ) ) ;
70
- console . log ( 'Bundling main process:\n' ) ;
69
+ const bundle = webpack ( mainConfig . toConfig ( ) )
70
+ console . log ( 'Bundling main process:\n' )
71
71
bundle . run ( ( err , stats ) => {
72
72
if ( err ) {
73
- console . error ( err . stack || err ) ;
73
+ console . error ( err . stack || err )
74
74
if ( err . details ) {
75
- console . error ( err . details ) ;
75
+ console . error ( err . details )
76
76
}
77
- process . exit ( 1 ) ;
77
+ process . exit ( 1 )
78
78
}
79
79
80
- const info = stats . toJson ( ) ;
80
+ const info = stats . toJson ( )
81
81
82
82
if ( stats . hasErrors ( ) ) {
83
- console . error ( info . errors ) ;
84
- process . exit ( 1 ) ;
83
+ console . error ( info . errors )
84
+ process . exit ( 1 )
85
85
}
86
86
87
87
if ( stats . hasWarnings ( ) ) {
88
- console . warn ( info . warnings ) ;
88
+ console . warn ( info . warnings )
89
89
}
90
90
91
91
console . log (
92
92
stats . toString ( {
93
93
chunks : false ,
94
94
colors : true
95
95
} )
96
- ) ;
96
+ )
97
97
98
- console . log ( '\nBuilding app with electron-builder:\n' ) ;
98
+ console . log ( '\nBuilding app with electron-builder:\n' )
99
99
100
100
builder
101
101
. build ( {
@@ -106,15 +106,15 @@ module.exports = (api, options) => {
106
106
} )
107
107
. then ( ( ) => {
108
108
// handle result
109
- console . log ( '\nBuild complete!\n' ) ;
109
+ console . log ( '\nBuild complete!\n' )
110
110
} )
111
111
. catch ( err => {
112
112
// handle error
113
- throw err ;
114
- } ) ;
115
- } ) ;
113
+ throw err
114
+ } )
115
+ } )
116
116
}
117
- ) ;
117
+ )
118
118
api . registerCommand (
119
119
'serve:electron' ,
120
120
{
@@ -123,61 +123,61 @@ module.exports = (api, options) => {
123
123
details : `See https://github.com/nklayman/vue-cli-plugin-electron-builder for more details.`
124
124
} ,
125
125
( ) => {
126
- const execa = require ( 'execa' ) ;
127
- const mainConfig = new Config ( ) ;
126
+ const execa = require ( 'execa' )
127
+ const mainConfig = new Config ( )
128
128
mainConfig
129
129
. mode ( 'development' )
130
130
. devtool ( 'source-map' )
131
131
. target ( 'electron-main' )
132
132
. node . set ( '__dirname' , false )
133
- . set ( '__filename' , false ) ;
133
+ . set ( '__filename' , false )
134
134
mainConfig . output
135
135
. path ( api . resolve ( './dist_electron' ) )
136
- . filename ( 'background.js' ) ;
136
+ . filename ( 'background.js' )
137
137
mainConfig . plugin ( 'uglify' ) . use ( UglifyJSPlugin , [
138
138
{
139
139
parallel : true ,
140
140
sourceMap : true
141
141
}
142
- ] ) ;
142
+ ] )
143
143
mainConfig
144
144
. plugin ( 'env' )
145
- . use ( webpack . EnvironmentPlugin , [ { NODE_ENV : 'development' } ] ) ;
146
- mainConfig . entry ( 'background' ) . add ( api . resolve ( './src/background.js' ) ) ;
147
- const bundle = webpack ( mainConfig . toConfig ( ) ) ;
145
+ . use ( webpack . EnvironmentPlugin , [ { NODE_ENV : 'development' } ] )
146
+ mainConfig . entry ( 'background' ) . add ( api . resolve ( './src/background.js' ) )
147
+ const bundle = webpack ( mainConfig . toConfig ( ) )
148
148
149
- console . log ( 'Bundling main process:\n' ) ;
149
+ console . log ( 'Bundling main process:\n' )
150
150
bundle . run ( ( err , stats ) => {
151
151
if ( err ) {
152
- console . error ( err . stack || err ) ;
152
+ console . error ( err . stack || err )
153
153
if ( err . details ) {
154
- console . error ( err . details ) ;
154
+ console . error ( err . details )
155
155
}
156
- process . exit ( 1 ) ;
156
+ process . exit ( 1 )
157
157
}
158
158
159
- const info = stats . toJson ( ) ;
159
+ const info = stats . toJson ( )
160
160
161
161
if ( stats . hasErrors ( ) ) {
162
- console . error ( info . errors ) ;
163
- process . exit ( 1 ) ;
162
+ console . error ( info . errors )
163
+ process . exit ( 1 )
164
164
}
165
165
166
166
if ( stats . hasWarnings ( ) ) {
167
- console . warn ( info . warnings ) ;
167
+ console . warn ( info . warnings )
168
168
}
169
169
170
170
console . log (
171
171
stats . toString ( {
172
172
chunks : false ,
173
173
colors : true
174
174
} )
175
- ) ;
175
+ )
176
176
177
- console . log ( '\nStarting development server:\n' ) ;
177
+ console . log ( '\nStarting development server:\n' )
178
178
179
179
api . service . run ( 'serve' ) . then ( server => {
180
- console . log ( '\nLaunching Electron...\n' ) ;
180
+ console . log ( '\nLaunching Electron...\n' )
181
181
const child = execa (
182
182
'./node_modules/.bin/electron dist_electron/background.js' ,
183
183
{
@@ -187,16 +187,16 @@ module.exports = (api, options) => {
187
187
WEBPACK_DEV_SERVER_URL : server . url
188
188
}
189
189
}
190
- ) ;
190
+ )
191
191
child . on ( 'exit' , ( ) => {
192
- process . exit ( 0 ) ;
193
- } ) ;
194
- } ) ;
195
- } ) ;
192
+ process . exit ( 0 )
193
+ } )
194
+ } )
195
+ } )
196
196
}
197
- ) ;
198
- } ;
197
+ )
198
+ }
199
199
module . exports . defaultModes = {
200
200
'build:electron' : 'production' ,
201
201
'serve:electron' : 'development'
202
- } ;
202
+ }
0 commit comments