Skip to content

Commit ac0a18e

Browse files
committed
[skip ci] update docs
1 parent d4d55c6 commit ac0a18e

File tree

3 files changed

+52
-40
lines changed

3 files changed

+52
-40
lines changed

docs/guide/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Then, install and invoke the generator of vue-cli-plugin-electron-builder by run
2323

2424
That's It! You're ready to go!
2525

26-
## To start a development server
26+
## To start a Development Server
2727

2828
If you use [Yarn](https://yarnpkg.com/en/) (strongly recommended):
2929

@@ -33,7 +33,7 @@ or if you use NPM:
3333

3434
`npm run serve:electron`
3535

36-
## To build your app
36+
## To Build Your App
3737

3838
With Yarn:
3939

docs/guide/configuration.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ sidebarDepth: 2
44

55
# Configuration
66

7+
## Table of Contents
8+
9+
[[toc]]
10+
711
## Configuring Electron Builder
812

913
To see available options, check out [Electron Builder Configuration Options](https://www.electron.build/configuration/configuration)
@@ -28,7 +32,7 @@ module.exports = {
2832
All CLI arguments passed to `build:electron` will be forwarded to electron-builder.
2933
:::
3034

31-
## Webpack configuration
35+
## Webpack Configuration
3236

3337
Your regular config is extended and used for bundling the renderer process (your app). To modify your webpack config for Electron builds only, use the `chainWebpackRendererProcess` function. To modify the webpack config for the [Electron main process](https://electronjs.org/docs/tutorial/application-architecture#main-and-renderer-processes) only, use the `chainWebpackMainProcess` function under VCP Electron Builder's plugin options in `vue.config.js`. To learn more about webpack chaining, see [webpack-chain](https://github.com/mozilla-neutrino/webpack-chain). These functions work similarly to the [`chainWebpack`](https://cli.vuejs.org/config/#chainwebpack) option provided by Vue CLI.
3438

@@ -64,7 +68,7 @@ module.exports = {
6468
}
6569
```
6670

67-
## Changing the output directory
71+
## Changing the Output Directory
6872

6973
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.
7074

@@ -100,6 +104,6 @@ module.exports = {
100104
}
101105
```
102106

103-
:::tip
104-
If you are adding typescript after vue-cli-plugin-electron-builder, you may also want to set `mainWindow`'s type to `any` and change `process.env.WEBPACK_DEV_SERVER_URL` to `process.env.WEBPACK_DEV_SERVER_URL as string` to fix type errors. If you add typescript first, this will be done automatically.
105-
:::
107+
:::tip Tip <Badge text="1.0.0-rc.1+" type="info"/>
108+
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.
109+
:::

docs/guide/guide.md

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,41 @@ sidebarDepth: 2
44

55
# Guide
66

7-
## Handling static assets
7+
## Table Of Contents
88

9-
### Renderer process (main app)
9+
[[toc]]
10+
11+
## Native Modules <Badge text="1.0.0-rc.1+" type="warn"/>
12+
13+
Native modules are supported and should work without any configuration. If you get errors, first make sure VCP-Electron-Builder's version is set to `1.0.0-rc.1` or greater. If it still fails, re-invoke the generator with `vue invoke electron-builder`. The generator will automatically detect missing code (such as native module support) and add it, without interfering with the rest. If you have done both these things, you may need to set the native dependency as an [webpack external](https://webpack.js.org/configuration/externals/). It should get found automatically, but it might not. To do this, use the `externals` option:
14+
15+
```javascript
16+
// vue.config.js
17+
module.exports = {
18+
pluginOptions: {
19+
electronBuilder: {
20+
// List native deps here if they don't work
21+
externals: ['my-native-dep']
22+
}
23+
}
24+
}
25+
```
26+
27+
::: tip
28+
29+
You can prefix an item in the `externals` array with `!` to prevent it being automatically marked as an external. (`!not-external`)
30+
31+
:::
32+
33+
::: tip
34+
35+
If you do not use native dependencies in your code, you can remove the `postinstall` script from your `package.json`. Native modules may not work, but dependency install times will be faster.
36+
37+
:::
38+
39+
## Handling Static Assets
40+
41+
### Renderer Process (Main App)
1042

1143
In the renderer process, static assets work similarly to a regular app. Read Vue CLI's documentation [here](https://cli.vuejs.org/guide/html-and-static-assets.html) before continuing. However, there are a few changes made:
1244

@@ -15,7 +47,7 @@ In the renderer process, static assets work similarly to a regular app. Read Vue
1547

1648
**Note: `__static` is not available in regular build/serve. It should only be used in electron to read/write files on disk. To import a file (img, script, etc...) and not have it be transpiled by webpack, use the `process.env.BASE_URL` instead.**
1749

18-
### Main process (background.js)
50+
### Main Process (`background.js`)
1951

2052
The main process won't have access to `process.env.BASE_URL` or `src/assets`. However, you can still use `__static` to get a path to your public directory in development and production.
2153

@@ -52,7 +84,7 @@ console.log(fileContents)
5284
│ ├── [application name] setup [version].[target binary (exe|dmg|rpm...)] # installer for Electron app
5385
│ ├── background.js # compiled background file used for serve:electron
5486
│ └── ...
55-
├── public/ # Files placed here will be avalible through __static or process.env.BASE_URL
87+
├── public/ # Files placed here will be available through __static or process.env.BASE_URL
5688
├── src/
5789
│ ├── background.[js|ts] # electron entry file (for Electron's main process)
5890
│ ├── [main|index].[js|ts] # your app's entry file (for Electron's render process)
@@ -61,48 +93,24 @@ console.log(fileContents)
6193
├── ...
6294
```
6395

64-
## Using Native Dependencies
65-
66-
To use native deps in Electron, you will need to find the path to the main file (`.node`) relative to `node_modules` for that dep. Once you have found it, set `vue.config.js` (replace `YOUR_DEP` with the name of the native dep and `YOUR_DEP_PATH` with the path to the main file) to:
67-
68-
```javascript
69-
module.exports = {
70-
pluginOptions: {
71-
electronBuilder: {
72-
chainWebpackRendererProcess: config => {
73-
config.module
74-
.rule('node-loader')
75-
.test(/\.node$/)
76-
.use('node')
77-
.loader('node-loader')
78-
config.resolve.alias.set('YOUR_DEP', 'YOUR_DEP_PATH')
79-
return config
80-
}
81-
}
82-
}
83-
}
84-
```
85-
86-
For example, if you were using SQlite3, `YOUR_DEP_PATH` would be `sqlite3/lib/binding/electron-v2.0-YOUR_PLATFORM_HERE-x64/node_sqlite3.node`
87-
8896
## How it works
8997

90-
### Build command
98+
### Build Command
9199

92100
The build command consists of three main phases: render build, main build, and electron-builder build:
93101

94102
1. Render build: This phase calls `vue-cli-service build` with some custom configuration so it works properly with electron. (The render process is your standard app.)
95-
2. Main build: This phase is where vue-cli-plugin-electron-builder bundles your background file for the main process (`src/background.js`).
103+
2. Main build: This phase is where VCP-Electron-Builder bundles your background file for the main process (`src/background.js`).
96104
3. Electron-builder build: This phase uses [electron-builder](https://www.electron.build) to turn your web app code into an desktop app powered by [Electron](https://electronjs.org).
97105

98-
### Serve command
106+
### Serve Command
99107

100108
The serve command also consists of 3 main phases: main build, dev server launch, and electron launch:
101109

102110
1. Dev server launch: This phase starts the built in dev server with a few modifications to work properly with electron.
103111
2. Main build: This phase, like in the build command, bundles your app's main process, but in development mode.
104112
3. Electron launch: This phase launches electron and tells it to load the url of the above dev server.
105113

106-
## Is this plugin production ready?
114+
## Is This Plugin Production Ready?
107115

108-
This plugin is nearly production ready. It has test coverage for everything but the UI interface and proper logging of errors. It needs to be used a little bit more in large applications before it is considered safe to use in a large production environment. Please try it in your app and report any bugs or feature requests.
116+
This plugin is nearly production ready. It has test coverage for everything but the UI interface and proper error logging. It needs to be used more in the real world to iron out the last few bugs before it is considered safe to use in a large production environment. Please try it in your app and report any bugs or feature requests.

0 commit comments

Comments
 (0)