You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guide/configuration.md
+9-5Lines changed: 9 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,10 @@ sidebarDepth: 2
4
4
5
5
# Configuration
6
6
7
+
## Table of Contents
8
+
9
+
[[toc]]
10
+
7
11
## Configuring Electron Builder
8
12
9
13
To see available options, check out [Electron Builder Configuration Options](https://www.electron.build/configuration/configuration)
@@ -28,7 +32,7 @@ module.exports = {
28
32
All CLI arguments passed to `build:electron` will be forwarded to electron-builder.
29
33
:::
30
34
31
-
## Webpack configuration
35
+
## Webpack Configuration
32
36
33
37
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.
34
38
@@ -64,7 +68,7 @@ module.exports = {
64
68
}
65
69
```
66
70
67
-
## Changing the output directory
71
+
## Changing the Output Directory
68
72
69
73
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.
70
74
@@ -100,6 +104,6 @@ module.exports = {
100
104
}
101
105
```
102
106
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 <Badgetext="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.
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)
10
42
11
43
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:
12
44
@@ -15,7 +47,7 @@ In the renderer process, static assets work similarly to a regular app. Read Vue
15
47
16
48
**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.**
17
49
18
-
### Main process (background.js)
50
+
### Main Process (`background.js`)
19
51
20
52
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.
21
53
@@ -52,7 +84,7 @@ console.log(fileContents)
52
84
│ ├── [application name] setup [version].[target binary (exe|dmg|rpm...)] # installer for Electron app
53
85
│ ├── background.js # compiled background file used for serve:electron
54
86
│ └── ...
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
56
88
├── src/
57
89
│ ├── background.[js|ts] # electron entry file (for Electron's main process)
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:
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
-
88
96
## How it works
89
97
90
-
### Build command
98
+
### Build Command
91
99
92
100
The build command consists of three main phases: render build, main build, and electron-builder build:
93
101
94
102
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`).
96
104
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).
97
105
98
-
### Serve command
106
+
### Serve Command
99
107
100
108
The serve command also consists of 3 main phases: main build, dev server launch, and electron launch:
101
109
102
110
1. Dev server launch: This phase starts the built in dev server with a few modifications to work properly with electron.
103
111
2. Main build: This phase, like in the build command, bundles your app's main process, but in development mode.
104
112
3. Electron launch: This phase launches electron and tells it to load the url of the above dev server.
105
113
106
-
## Is this plugin production ready?
114
+
## Is This Plugin Production Ready?
107
115
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