@@ -2,6 +2,11 @@ const UglifyJSPlugin = require('uglifyjs-webpack-plugin')
2
2
const webpack = require ( 'webpack' )
3
3
const Config = require ( 'webpack-chain' )
4
4
module . exports = ( api , options ) => {
5
+ const pluginOptions =
6
+ options . pluginOptions && options . pluginOptions . electronBuilder
7
+ ? options . pluginOptions . electronBuilder
8
+ : { }
9
+ const outputDir = pluginOptions . outputDir || 'dist_electron'
5
10
api . registerCommand (
6
11
'build:electron' ,
7
12
{
@@ -14,37 +19,32 @@ module.exports = (api, options) => {
14
19
`See https://github.com/nklayman/vue-cli-plugin-electron-builder for more details.`
15
20
} ,
16
21
async ( ) => {
17
- const buildRenderer = require ( '@vue/cli-service/lib/commands/build' )
18
- . build
22
+ const buildRenderer = require ( '@vue/cli-service/lib/commands/build' ) . build
19
23
const fs = require ( 'fs-extra' )
20
24
const builder = require ( 'electron-builder' )
21
25
const rendererConfig = api . resolveChainableWebpackConfig ( )
22
26
const defaultBuildConfig = {
23
27
directories : {
24
- output : 'dist_electron'
28
+ output : outputDir
25
29
} ,
26
- files : [ 'dist/**/*' , 'node_modules/**/*' , 'package.json' ] ,
30
+ files : [
31
+ outputDir + '/bundled/**/*' ,
32
+ 'node_modules/**/*' ,
33
+ 'package.json'
34
+ ] ,
27
35
extends : null
28
36
}
29
- const userBuildConfig = ( function ( ) {
30
- if (
31
- options . pluginOptions &&
32
- options . pluginOptions . electronBuilder &&
33
- options . pluginOptions . electronBuilder . builderConfig
34
- ) {
35
- return options . pluginOptions . electronBuilder . builderConfig
36
- } else {
37
- return { }
38
- }
39
- } ) ( )
37
+ const userBuildConfig = pluginOptions . userBuildConfig || { }
40
38
const mainConfig = new Config ( )
41
39
mainConfig
42
40
. mode ( 'production' )
43
41
. devtool ( 'source-map' )
44
42
. target ( 'electron-main' )
45
43
. node . set ( '__dirname' , false )
46
44
. set ( '__filename' , false )
47
- mainConfig . output . path ( api . resolve ( './dist' ) ) . filename ( 'background.js' )
45
+ mainConfig . output
46
+ . path ( api . resolve ( outputDir + '/bundled' ) )
47
+ . filename ( 'background.js' )
48
48
mainConfig . plugin ( 'uglify' ) . use ( UglifyJSPlugin , [
49
49
{
50
50
parallel : true ,
@@ -58,12 +58,17 @@ module.exports = (api, options) => {
58
58
59
59
console . log ( 'Bundling render process:' )
60
60
rendererConfig . target ( 'electron-renderer' ) . output . publicPath ( './' )
61
- await buildRenderer ( { _ : [ ] } , api , options , rendererConfig )
61
+ await buildRenderer (
62
+ { _ : [ ] , dest : outputDir + '/bundled' } ,
63
+ api ,
64
+ options ,
65
+ rendererConfig
66
+ )
62
67
if ( fs . existsSync ( api . resolve ( './dist/fonts' ) ) ) {
63
68
fs . mkdirSync ( api . resolve ( './dist/css/fonts' ) )
64
69
fs . copySync (
65
- api . resolve ( './dist /fonts') ,
66
- api . resolve ( './dist /css/fonts')
70
+ api . resolve ( outputDir + '/bundled /fonts') ,
71
+ api . resolve ( outputDir + '/bundled /css/fonts')
67
72
)
68
73
}
69
74
const bundle = webpack ( mainConfig . toConfig ( ) )
@@ -131,9 +136,7 @@ module.exports = (api, options) => {
131
136
. target ( 'electron-main' )
132
137
. node . set ( '__dirname' , false )
133
138
. set ( '__filename' , false )
134
- mainConfig . output
135
- . path ( api . resolve ( './dist_electron' ) )
136
- . filename ( 'background.js' )
139
+ mainConfig . output . path ( api . resolve ( outputDir ) ) . filename ( 'background.js' )
137
140
mainConfig . plugin ( 'uglify' ) . use ( UglifyJSPlugin , [
138
141
{
139
142
parallel : true ,
@@ -179,7 +182,7 @@ module.exports = (api, options) => {
179
182
api . service . run ( 'serve' ) . then ( server => {
180
183
console . log ( '\nLaunching Electron...\n' )
181
184
const child = execa (
182
- ' ./node_modules/.bin/electron dist_electron /background.js' ,
185
+ ` ./node_modules/.bin/electron ${ outputDir } /background.js` ,
183
186
{
184
187
cwd : api . resolve ( '.' ) ,
185
188
stdio : 'inherit' ,
0 commit comments