Skip to content

Commit 7f922c0

Browse files
committed
docs: add security page and remove minimum version notices
1 parent 096d3b1 commit 7f922c0

File tree

7 files changed

+73
-54
lines changed

7 files changed

+73
-54
lines changed

docs/.vuepress/config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
22
title: 'Vue CLI Plugin Electron Builder',
33
description:
4-
'A Vue CLI 3 plugin for Electron with no required configuration.',
4+
'A Vue CLI 3/4 plugin for Electron with no required configuration.',
55
base: '/vue-cli-plugin-electron-builder/',
66
ga: 'UA-134189455-2',
77
head: [
@@ -35,6 +35,7 @@ module.exports = {
3535
'guide',
3636
'configuration',
3737
'recipes',
38+
'security',
3839
'testingAndDebugging',
3940
'commonIssues'
4041
]

docs/guide/README.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,3 @@ With Yarn:
3838
or with NPM:
3939

4040
`npm run electron:build`
41-
42-
::: warning
43-
The command names have changed in `v1.0.0-rc.4`. If you are using an older version, the command names are:
44-
`yarn serve:electron`
45-
and
46-
`yarn build:electron`.
47-
48-
Replace `yarn` with `npm run` if you are using npm.
49-
:::

docs/guide/commonIssues.md

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,34 +32,18 @@ if (isDevelopment && !process.env.IS_TEST) {
3232
}
3333
```
3434

35-
## Strict mime-type error when running a built app
36-
37-
:::tip Notice
38-
As of v1.0.0-rc.5, this tag is no longer necessary. You can remove it if you wish.
39-
:::
40-
41-
This is likely caused because you are missing code in your `public/index.html` file. To add it, simply run `vue invoke electron-builder`. This will re-invoke the generator of VCP Electron Builder. Any missing code will be detected and added automatically. If you would not like to re-invoke the generator, you can paste this code into the top of the `<head>` of your `public/index.html`:
42-
43-
```html
44-
<% if (BASE_URL === './') { %><base href="app://./" /><% } %>
45-
```
46-
4735
## Exceptions in `async` functions not getting logged to console
4836

4937
This bug can be fixed by adding the following code to the entrypoint of your Vue App `src/main.js`:
5038

5139
```javascript
52-
process.on('unhandledRejection', error => {
40+
process.on('unhandledRejection', (error) => {
5341
console.error(error)
5442
})
5543
```
5644

5745
See [#118](https://github.com/nklayman/vue-cli-plugin-electron-builder/issues/118) for more details. Thanks to [dspangenberg](https://github.com/dspangenberg) for the fix.
5846

59-
## Electron not opening on Node v11
60-
61-
Make sure you are using Electron v2.0.14+ or v3.0.10+. Also, make sure Node is v11.2.0+. See [#107 (comment)](https://github.com/nklayman/vue-cli-plugin-electron-builder/issues/107#issuecomment-441168465) for more details.
62-
6347
## Other issues
6448

6549
Many issues can be solved by re-invoking the generator of Vue CLI Plugin Electron Builder. This allows it to add newer code to your project files. You may need to do this after upgrading the plugin.

docs/guide/configuration.md

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ module.exports = {
4747
},
4848
pluginOptions: {
4949
electronBuilder: {
50-
chainWebpackMainProcess: config => {
50+
chainWebpackMainProcess: (config) => {
5151
// Chain webpack config for electron main process only
5252
},
53-
chainWebpackRendererProcess: config => {
53+
chainWebpackRendererProcess: (config) => {
5454
// Chain webpack config for electron renderer process only
5555
// The following example will set IS_ELECTRON to true in your app
56-
config.plugin('define').tap(args => {
56+
config.plugin('define').tap((args) => {
5757
args[0]['IS_ELECTRON'] = true
5858
return args
5959
})
@@ -63,7 +63,7 @@ module.exports = {
6363
// Provide an array of files that, when changed, will recompile the main process and restart Electron
6464
// Your main process file will be added by default
6565
mainProcessWatch: ['src/myFile1', 'src/myFile2'],
66-
// [1.0.0-rc.4+] Provide a list of arguments that Electron will be launched with during "electron:serve",
66+
// Provide a list of arguments that Electron will be launched with during "electron:serve",
6767
// which can be accessed from the main process (src/background.js).
6868
// Note that it is ignored when --debug flag is used with "electron:serve", as you must launch Electron yourself
6969
// Command line args (excluding --debug, --dashboard, and --headless) are passed to Electron as well
@@ -73,25 +73,11 @@ module.exports = {
7373
}
7474
```
7575

76-
## Node Integration
77-
78-
As of v2.0, electron `nodeIntegration` is disabled by default. This blocks all node APIs such as `require`. This reduces [security risks](https://electronjs.org/docs/tutorial/security#2-do-not-enable-nodejs-integration-for-remote-content), and is a recommended best practice by the electron team. If you need to use native modules such as `fs` or `sqlite` in the renderer process, you can enable `nodeIntegration` in `vue.config.js`:
79-
80-
```js
81-
module.exports = {
82-
pluginOptions: {
83-
electronBuilder: {
84-
nodeIntegration: true
85-
}
86-
}
87-
}
88-
```
89-
9076
## Changing the Output Directory
9177

92-
If you don't want your files outputted into dist_electron, you can choose a custom folder in vue-cli-plugin-electron-builder's plugin options. If you are using `v1.0.0-rc.4` or later, you can use the `--dest` argument to change the output dir as well.
78+
If you don't want your files outputted into dist_electron, you can choose a custom folder in VCPEB's plugin options. You can use the `--dest` argument to change the output dir as well.
9379

94-
**Note: If you are using version 1.0.0-rc.3 or lower, after changing this, you MUST update the main field of your `package.json` to `[new dir]/bundled/background.js`. It is also recommended to add the new directory to your .gitignore file.**
80+
**Note: It is recommended to add the new directory to your .gitignore file.**
9581

9682
```javascript
9783
// vue.config.js
@@ -123,11 +109,11 @@ module.exports = {
123109
}
124110
```
125111

126-
:::tip Tip <Badge text="1.0.0-rc.1+" type="info"/>
112+
:::tip Tip
127113
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.
128114
:::
129115

130-
## Changing the File Loading Protocol <Badge text="1.0.0+" type="info"/>
116+
## Changing the File Loading Protocol
131117

132118
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.
133119

@@ -150,11 +136,11 @@ win.loadURL('myCustomProtocol://./index.html') // Change it here as well
150136
// ...
151137
```
152138

153-
## Bundling Options <Badge text="1.0.0-rc.3+" type="info"/>
139+
## Bundling Options
154140

155141
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.
156142

157-
## Electron's Junk Terminal Output <Badge text="1.0.0-rc.3+" type="info"/>
143+
## Electron's Junk Terminal Output
158144

159145
Electron will sometimes produce a bunch of junk output like so:
160146

@@ -181,7 +167,7 @@ VCP Electron Builder will automatically remove this for you (powered by [run-ele
181167
module.exports = {
182168
pluginOptions: {
183169
electronBuilder: {
184-
removeElectronJunk: false // True by default
170+
removeElectronJunk: false
185171
}
186172
}
187173
}

docs/guide/guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ win = new BrowserWindow({
125125

126126
## Env Variables
127127

128-
Read [Vue ClI's documentation](https://cli.vuejs.org/guide/mode-and-env.html) to learn about using environment variables in your app. All env variables prefixed with `VUE_APP_` will be available in both the main and renderer processes (Only available in main process since `1.0.0-rc.4`).
128+
Read [Vue ClI's documentation](https://cli.vuejs.org/guide/mode-and-env.html) to learn about using environment variables in your app. All env variables prefixed with `VUE_APP_` will be available in both the main and renderer processes.
129129

130130
## How it works
131131

docs/guide/recipes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ win = new BrowserWindow({
158158
If you get the linting error `'__static' is not defined`, add `/* global __static */` in your background file above your imports.
159159
:::
160160

161-
## Multiple Pages <badge text="v1.1.1+" type="info" />
161+
## Multiple Pages
162162

163163
> Create multiple Electron windows for each [page](https://cli.vuejs.org/config/#pages)
164164

docs/guide/security.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Security
2+
3+
[[toc]]
4+
5+
## Node Integration
6+
7+
As of v2.0 of VCPEB, Electron `nodeIntegration` is disabled by default. This blocks all node APIs such as `require`. This reduces [security risks](https://electronjs.org/docs/tutorial/security#2-do-not-enable-nodejs-integration-for-remote-content), and is a recommended best practice by the Electron team. If you need to use native modules such as `fs` or `sqlite` in the renderer process, you can enable `nodeIntegration` in `vue.config.js`:
8+
9+
```js
10+
module.exports = {
11+
pluginOptions: {
12+
electronBuilder: {
13+
nodeIntegration: true
14+
}
15+
}
16+
}
17+
```
18+
19+
:::tip IPC With Node Integration
20+
You can still use [IPC](https://www.electronjs.org/docs/api/ipc-renderer) with `nodeIntegration`. Just create a [preload script](./guide.html#preload-files) with the following code:
21+
22+
```js
23+
import { ipcRenderer } from 'electron'
24+
window.ipcRenderer = ipcRenderer
25+
```
26+
27+
Now, you can access `ipcRenderer` with `window.ipcRenderer` in your Vue app.
28+
:::
29+
30+
## Loading Local Images/Resources
31+
32+
If WebSecurity is enabled, you won't be able to load resources from the file system, ie `<img src="file://image.png"/>`. [Disabling WebSecurity is strongly discouraged](https://www.electronjs.org/docs/tutorial/security#5-do-not-disable-websecurity), so you should instead use the following technique to load local resources and keep WebSecurity enabled.
33+
34+
Add the following to your main process file (`background.(js|ts)` by default):
35+
36+
```js
37+
app.on('ready', () => {
38+
registerLocalResourceProtocol()
39+
...
40+
})
41+
42+
function registerLocalResourceProtocol() {
43+
protocol.registerFileProtocol('local-resource', (request, callback) => {
44+
const url = request.url.replace(/^local-resource:\/\//, '')
45+
// Decode URL to prevent errors when loading filenames with UTF-8 chars or chars like "#"
46+
const decodedUrl = decodeURI(url) // Needed in case URL contains spaces
47+
try {
48+
return callback(decodedUrl)
49+
}
50+
catch (error) {
51+
console.error('ERROR: registerLocalResourceProtocol: Could not get file path:', error)
52+
}
53+
})
54+
}
55+
```
56+
57+
Then, simply prefix local image urls with `local-resource://`, ie `<img src="local-resource://image.png"/>`

0 commit comments

Comments
 (0)