File tree Expand file tree Collapse file tree 5 files changed +68
-11
lines changed Expand file tree Collapse file tree 5 files changed +68
-11
lines changed Original file line number Diff line number Diff line change
1
+ const fs = require ( 'fs' )
2
+
1
3
module . exports = api => {
2
4
api . render ( './template' )
5
+ // Read existing index.html and .gitignore
6
+ let index = fs . readFileSync ( api . resolve ( './public/index.html' ) , 'utf8' )
7
+ let gitignore = fs . readFileSync ( api . resolve ( './.gitignore' ) , 'utf8' )
8
+ // Add base element inside <head> tag
9
+ index = index . replace (
10
+ / ^ \s * ?< h e a d .* ?> \s * ?$ / m,
11
+ `<head>\n <% if (BASE_URL === './') { %><base href="app://./" /><% } %>`
12
+ )
13
+ // Add /dist_electron to gitignore
14
+ gitignore = gitignore + '\n#Electron-builder output\n/dist_electron'
15
+ api . onCreateComplete ( ( ) => {
16
+ // Write updated files
17
+ fs . writeFileSync ( api . resolve ( './public/index.html' ) , index )
18
+ fs . writeFileSync ( api . resolve ( './.gitignore' ) , gitignore )
19
+ } )
3
20
api . extendPackage ( {
4
21
scripts : {
5
22
'build:electron' : 'vue-cli-service build:electron' ,
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
- import { app , BrowserWindow } from 'electron'
3
+ import { app , protocol , BrowserWindow } from 'electron'
4
4
import * as path from 'path'
5
5
import { format as formatUrl } from 'url'
6
+ import createProtocol from 'vue-cli-plugin-electron-builder/lib/createProtocol'
6
7
7
8
const isDevelopment = process . env . NODE_ENV !== 'production'
8
9
9
10
// global reference to mainWindow (necessary to prevent window from being garbage collected)
10
11
let mainWindow
11
12
13
+ // Standard scheme must be registered before the app is ready
14
+ protocol . registerStandardSchemes ( [ 'app' ] , { secure : true } )
12
15
function createMainWindow ( ) {
13
16
const window = new BrowserWindow ( )
14
17
@@ -17,6 +20,7 @@ function createMainWindow () {
17
20
// Load the url of the dev server if in development mode
18
21
window . loadURL ( process . env . WEBPACK_DEV_SERVER_URL )
19
22
} else {
23
+ createProtocol ( 'app' )
20
24
// Load the index.html when not in development
21
25
window . loadURL (
22
26
formatUrl ( {
Original file line number Diff line number Diff line change @@ -71,7 +71,9 @@ module.exports = (api, options) => {
71
71
// For the cli-ui webpack dashboard
72
72
dashboard : args . dashboard ,
73
73
// Make sure files are outputted to proper directory
74
- dest : outputDir + '/bundled'
74
+ dest : outputDir + '/bundled' ,
75
+ // Enable modern mode
76
+ modern : true
75
77
}
76
78
const mainConfig = new Config ( )
77
79
// Configure main process webpack config
@@ -105,7 +107,8 @@ module.exports = (api, options) => {
105
107
. loader ( 'ts-loader' )
106
108
. options ( { transpileOnly : ! mainProcessTypeChecking } )
107
109
}
108
-
110
+ // Set the base url so that the app protocol is used
111
+ options . baseUrl = './'
109
112
console . log ( 'Bundling render process:' )
110
113
// Build the render process with the custom args and config
111
114
await buildRenderer ( vueArgs , api , options , rendererConfig )
@@ -253,7 +256,6 @@ module.exports = (api, options) => {
253
256
colors : true
254
257
} )
255
258
)
256
-
257
259
console . log ( '\nStarting development server:\n' )
258
260
// Run the serve command with custom webpack config
259
261
serve (
Original file line number Diff line number Diff line change
1
+ import { protocol } from 'electron'
2
+ import * as path from 'path'
3
+ import { readFile } from 'fs'
4
+ import { URL } from 'url'
5
+
6
+ export default scheme => {
7
+ protocol . registerBufferProtocol (
8
+ scheme ,
9
+ ( request , respond ) => {
10
+ let pathName = new URL ( request . url ) . pathname
11
+ pathName = decodeURI ( pathName ) // Needed in case URL contains spaces
12
+
13
+ readFile ( path . join ( __dirname , pathName ) , ( error , data ) => {
14
+ if ( error ) {
15
+ console . error ( `Failed to register ${ scheme } protocol` , error )
16
+ }
17
+ let extension = path . extname ( pathName ) . toLowerCase ( )
18
+ let mimeType = ''
19
+
20
+ if ( extension === '.js' ) {
21
+ mimeType = 'text/javascript'
22
+ } else if ( extension === '.html' ) {
23
+ mimeType = 'text/html'
24
+ } else if ( extension === '.css' ) {
25
+ mimeType = 'text/css'
26
+ } else if ( extension === '.svg' || extension === '.svgz' ) {
27
+ mimeType = 'image/svg+xml'
28
+ } else if ( extension === '.json' ) {
29
+ mimeType = 'application/json'
30
+ }
31
+
32
+ respond ( { mimeType, data } )
33
+ } )
34
+ } ,
35
+ error => {
36
+ if ( error ) {
37
+ console . error ( `Failed to register ${ scheme } protocol` , error )
38
+ }
39
+ }
40
+ )
41
+ }
You can’t perform that action at this time.
0 commit comments