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
A Vue Cli 3 plugin for Electron with no required configuration that uses [Electron Builder](https://www.electron.build/) and [Electron Webpack](https://webpack.electron.build/).
4
+
A Vue Cli 3 plugin for Electron with no required configuration that uses [Electron Builder](https://www.electron.build/).
4
5
5
6
**IMPORTANT: Your app must be created with Vue-CLI 3 (vue create my-app), will not work with Vue-CLI 2 (vue init webpack my-app)!**
6
7
8
+
**IMPORTANT: This is the alpha version of vue-cli-plugin-electron-builder! It is only recommended that you use this if you want to test it out and report bugs, not in production. Check back soon for a beta release.**
9
+
7
10
## Quick Start:
8
11
9
12
Open a terminal in the directory of your app created with Vue-CLI 3.
@@ -12,7 +15,7 @@ Then, install and invoke the generator of vue-cli-plugin-electron-builder by run
12
15
13
16
`vue add electron-builder`
14
17
15
-
That's It! Your ready to go!
18
+
That's It! You're ready to go!
16
19
17
20
### To start a development server:
18
21
@@ -26,7 +29,7 @@ or if you use NPM:
26
29
27
30
### To build your app:
28
31
29
-
With yarn:
32
+
With Yarn:
30
33
31
34
`yarn build:electron`
32
35
@@ -37,101 +40,105 @@ or with NPM:
37
40
### Folder Structure:
38
41
39
42
```
40
-
├── dist/ # where electron-webpack outputs compiled files (this will overwrite normal build files)
41
-
42
-
│ └── ...
43
-
44
43
├── dist_electron/
45
-
46
-
│ ├── [target platform]-unpacked # unpacked Electron app (main exe and supporting files)
47
-
48
-
│ ├── [application name] setup [version].[target binary (exe|dmg|rpm...)] # installer for Electron app
49
-
44
+
│ ├── bundled/.. # where webpack outputs compiled files
45
+
│ ├── [target platform]-unpacked/.. # unpacked Electron app (main app and supporting files)
46
+
│ ├── [application name] setup [version].[target binary (exe|dmg|rpm...)] # installer for Electron app
47
+
│ ├── background.js # compiled background file used for serve:electron
50
48
│ └── ...
51
-
52
49
├── src/
53
-
54
-
│ ├─── main/
55
-
56
-
│ │ └── [main|index].[js|ts] # Electron entry file (for Electron's main process)
├── electron-builder.[json|yml] # electron-builder configuration options (can also be placed in package.json under the "build" key)
63
-
64
-
├── electron-webpack.[json|yml] # electron-webpack configuration options (can also be placed in package.json under the "electronWebpack" key)
65
-
66
-
├── package.json # your app's package.json file
67
-
53
+
├── package.json # your app's package.json file
68
54
├── ...
69
55
```
70
56
71
-
## Further Configuration:
72
-
73
-
Initial configuration is already set for you in your app's package.json, but if you want to modify it:
57
+
## Configuration:
74
58
75
-
### CLI Options:
76
-
77
-
When building your app, any arguments will be passed to electron-builder. To pass an argument/arguments to electron-webpack, place them after --webpack.
To see avalible options, check out [Electron Builder Configuration Options](https://www.electron.build/configuration/configuration)
86
62
87
-
As per Electron Builder's documentation, they can be applied:
88
-
89
-
> * in the `package.json` file of your project using the `build` key on the top level:
90
-
>
91
-
> ```
92
-
> "build": {
93
-
> "appId": "com.example.app"
94
-
> }
95
-
> ```
96
-
>
97
-
> * or through the `--config <path/to/yml-or-json5-or-toml>` option (defaults to `electron-builder.yml`(or `json`, or [json5](http://json5.org/), or [toml](https://github.com/toml-lang/toml))).
98
-
>
99
-
> ```
100
-
> appId: "com.example.app"
101
-
> ```
102
-
>
103
-
> If you want to use [toml](https://en.wikipedia.org/wiki/TOML), please install `yarn add toml --dev`.
104
-
>
105
-
> Most of the options accept `null` — for example, to explicitly set that DMG icon must be default volume icon from the OS and default rules must be not applied (i.e. use application icon as DMG icon), set `dmg.icon` to `null`
106
-
107
-
### Electron Webpack:
108
-
109
-
To see avalible options, check out [Electron Webpack Configuration Options](https://webpack.electron.build/configuration)
63
+
They can be placed under the `builderOptions` key in vue-cli-plugin-electron-builder's plugin options in `vue.config.js`
64
+
```javascript
65
+
// vue.config.js
110
66
111
-
As per Electron Webpack's documentation, they can be applied:
67
+
module.exports= {
68
+
pluginOptions: {
69
+
electronBuilder: {
70
+
builderOptions: {
71
+
// options placed here will be merged with default configuration and passed to electron-builder
72
+
}
73
+
}
74
+
}
75
+
}
76
+
```
77
+
### Webpack configuration:
78
+
Your regular config is used for bundling the renderer process (your app). To modify the webpack config for the electron main process only, use the `chainWebpackMainProcess` function under vue-cli-plugin-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). The function should take a config argument, modify it through webpack-chain, and then return it.
79
+
80
+
**Note: Do NOT change the webpack output directory for the main process! See changing output directory below for more info. To change the entry point for the main process, use the `mainProcessFile` key, DO NOT modify it in through chaining.**
81
+
82
+
```javascript
83
+
// vue.config.js
112
84
113
-
> in `package.json` at `electronWebpack` or in a separate `electron-webpack.(json|json5|yml)`.
85
+
module.exports= {
86
+
configureWebpack: {
87
+
// Configuration applied to all builds
88
+
},
89
+
pluginOptions: {
90
+
electronBuilder: {
91
+
chainWebpackMainProcess: (config) => {
92
+
// Chain webpack config for electron main process only
93
+
},
94
+
mainProcessFile:'src/myBackgroundFile.js'
95
+
}
96
+
}
97
+
};
98
+
```
114
99
115
-
To modify the webpack config for electron builds only, use the webpackConfig object under vue-cli-plugin-electron-builder's plugin options in `vue.config.js`.
100
+
### Changing the output directory:
101
+
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.
102
+
**Note: 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.**
103
+
```javascript
104
+
// vue.config.js
116
105
106
+
module.exports= {
107
+
pluginOptions: {
108
+
electronBuilder: {
109
+
outputDir:'electron-builder-output-dir'
110
+
}
111
+
}
112
+
};
117
113
```
114
+
### Adding TypeScript Support:
115
+
Typescript support is automatic and requires no configuration, just add the `@vue/typescript` cli plugin. There are a few options for configuring typescript if necessary:
116
+
117
+
```javascript
118
118
// vue.config.js
119
119
120
-
module.exports = {
121
-
configureWebpack: {
122
-
// Non-electron build/serve configuration
123
-
// Aliases will be automatically copied from standard config to electron config
124
-
},
120
+
module.exports= {
125
121
pluginOptions: {
126
122
electronBuilder: {
127
-
webpackConfig: {
128
-
// your electron-only webpack config
129
-
}
123
+
disableMainProcessTypescript:false, // Manually disable typescript plugin for main process. Enable if you want to use regular js for the main process (src/background.js by default).
124
+
mainProcessTypeChecking:false// Manually enable type checking during webpck bundling for background file.
130
125
}
131
126
}
132
127
};
133
128
```
129
+
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.
130
+
131
+
## How it works:
132
+
### Build command:
133
+
The build command consists of three main phases: render build, main build, and electron-builder build:
134
+
135
+
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.)
136
+
2. Main build: This phase is where vue-cli-plugin-electron-builder bundles your background file for the main process (`src/background.js`).
137
+
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).
134
138
135
-
#### Adding TypeScript Support:
139
+
### Serve command:
140
+
The serve command also consists of 3 main phases: main build, dev server launch, and electron launch:
136
141
137
-
When you invoke/add vue-cli-plugin-electron-builder, it will ask you if you use TypeScript and configure accordingly. However, if you answered no and decide to add TypeScript later on, you must install electron-webpack-ts: `yarn add electron-webpack-ts --dev` (or with NPM: `npm install --save-dev electron-webpack-ts`).
142
+
1. Main build: This phase, like in the build command, bundles your app's main process, but in development mode.
143
+
2. Dev server launch: This phase starts the built in dev server with no special arguments, just hosting your app as normal.
144
+
3. Electron launch: This phase launches electron and tells it to load the url of the above dev server.
0 commit comments