Skip to content

Commit 3bf42d4

Browse files
committed
feat(build): allow changing file loading protocol, fixes #183
1 parent e99bba0 commit 3bf42d4

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

__tests__/commands.spec.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,20 +299,22 @@ describe('electron:build', () => {
299299
)
300300
})
301301

302-
test('Base url is set to "app://./"', async () => {
302+
test('Base url/public path is set to "app://./"', async () => {
303303
const { options } = await runCommand('electron:build')
304304
expect(options.baseUrl).toBe('app://./')
305+
expect(options.publicPath).toBe('app://./')
305306
})
306307

307-
test('Base url is set to "./" if pluginOptions.noAppProtocol is set', async () => {
308+
test('Custom file protocol is used if set', async () => {
308309
const { options } = await runCommand('electron:build', {
309310
pluginOptions: {
310311
electronBuilder: {
311-
noAppProtocol: true
312+
customFileProtocol: 'expected'
312313
}
313314
}
314315
})
315-
expect(options.baseUrl).toBe('./')
316+
expect(options.baseUrl).toBe('expected')
317+
expect(options.publicPath).toBe('expected')
316318
})
317319
})
318320

docs/guide/configuration.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,26 @@ module.exports = {
113113
If you decide to add the `@vue/typescript` plugin to your app later on, make sure to re-invoke the generator of VCP-Electron-Builder with `vue invoke electron-builder`. This will automatically insert missing type definitions to your `background.ts` file.
114114
:::
115115

116+
## Changing the File Loading Protocol <Badge text="1.0.0+" type="info"/>
117+
118+
By default, the `app` protocol is used to load files. This allows you to use ES6 `type="module"` scripts, created by Vue CLI's [modern mode](https://cli.vuejs.org/guide/browser-compatibility.html#modern-mode). If, for some reason, you would like to use a different protocol, set it with the `customFileProtocol` option, and change it in your `background.js` file.
119+
120+
```javascript
121+
// vue.config.js
122+
module.exports = {
123+
pluginOptions: {
124+
electronBuilder: {
125+
customFileProtocol: 'myCustomProtocol://' // You can also revert back to the file protocol with 'file://'
126+
}
127+
}
128+
}
129+
130+
// src/background.js
131+
// ...
132+
win.loadURL('myCustomProtocol://./index.html') // Change it here as well
133+
// ...
134+
```
135+
116136
## Bundling Options <Badge text="1.0.0-rc.3+" type="info"/>
117137

118138
By default, the app is built in [modern mode](https://cli.vuejs.org/guide/browser-compatibility.html#modern-mode). To disable this, use the `--legacy` argument in the `electron:build` command. If your app is already bundled and just needs to be built with electron-builder, pass the `--skipBundle` arg.

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ module.exports = (api, options) => {
105105
modern: !args.legacy
106106
}
107107
// Set the base url so that the app protocol is used
108-
options.baseUrl = pluginOptions.noAppProtocol ? './' : 'app://./'
108+
options.baseUrl = pluginOptions.customFileProtocol || 'app://./'
109109
// Set publicPath as well (replaced baseUrl since @vue/cli 3.3.0)
110-
options.publicPath = pluginOptions.noAppProtocol ? './' : 'app://./'
110+
options.publicPath = pluginOptions.customFileProtocol || 'app://./'
111111
info('Bundling render process:')
112112
// Build the render process with the custom args
113113
await api.service.run('build', vueArgs)

0 commit comments

Comments
 (0)