Skip to content

Commit 8dc5bba

Browse files
committed
fix(generator/background): use app protocol for index.html, fixes #129
1 parent f18e29d commit 8dc5bba

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

generator/template/src/background.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function createWindow () {
2424
} else {
2525
createProtocol('app')
2626
// Load the index.html when not in development
27-
win.loadFile('index.html')
27+
win.loadURL('app://./index.html')
2828
}
2929

3030
win.on('closed', () => {

lib/webpackConfig.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const fs = require('fs')
33
async function chainWebpack (api, pluginOptions, config) {
44
const rendererProcessChain =
55
pluginOptions.chainWebpackRendererProcess || (config => config)
6+
const realDirname = 'require("electron").remote.app.getAppPath()'
67
if (process.env.IS_ELECTRON) {
78
// Add externals
89
config.externals(getExternals(api, pluginOptions))
@@ -14,8 +15,10 @@ async function chainWebpack (api, pluginOptions, config) {
1415
if (process.env.NODE_ENV === 'production') {
1516
// Set process.env.BASE_URL and __static to absolute file path
1617
config.plugin('define').tap(args => {
17-
args[0]['process.env'].BASE_URL = '__dirname'
18-
args[0].__static = '__dirname'
18+
args[0].__dirname = realDirname
19+
args[0].__filename = `\`\${${realDirname}}/index.html\``
20+
args[0]['process.env'].BASE_URL = realDirname
21+
args[0].__static = realDirname
1922
return args
2023
})
2124
} else if (process.env.NODE_ENV === 'development') {

0 commit comments

Comments
 (0)