|
| 1 | +# Vue CLI Plugin Electron Builder |
| 2 | + |
| 3 | +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 | + |
| 5 | +**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 | +## Quick Start: |
| 8 | + |
| 9 | +Open a terminal in the directory of your app created with Vue-CLI 3. |
| 10 | + |
| 11 | +Then, install and invoke the generator of vue-cli-plugin-electron-builder by running: |
| 12 | + |
| 13 | +`vue add electron-builder` |
| 14 | + |
| 15 | +That's It! Your ready to go! |
| 16 | + |
| 17 | +### To start a development server: |
| 18 | + |
| 19 | +If you use [Yarn](https://yarnpkg.com/en/) (strongly recommended): |
| 20 | + |
| 21 | +`yarn serve:electron` |
| 22 | + |
| 23 | +or if you use NPM: |
| 24 | + |
| 25 | +`npm run serve:electron` |
| 26 | + |
| 27 | +### To build your app: |
| 28 | + |
| 29 | +With yarn: |
| 30 | + |
| 31 | +`yarn build:electron` |
| 32 | + |
| 33 | +or with NPM: |
| 34 | + |
| 35 | +`npm run build:electron` |
| 36 | + |
| 37 | +### Folder Structure: |
| 38 | + |
| 39 | +``` |
| 40 | +├── dist/ # where electron-webpack outputs compiled files (this will overwrite normal build files) |
| 41 | +
|
| 42 | +│ └── ... |
| 43 | +
|
| 44 | +├── 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 | +
|
| 50 | +│ └── ... |
| 51 | +
|
| 52 | +├── src/ |
| 53 | +
|
| 54 | +│ ├─── main/ |
| 55 | +
|
| 56 | +│ │ └── [main|index].[js|ts] # Electron entry file (for Electron's main process) |
| 57 | +
|
| 58 | +│ ├── [main|index].[js|ts] # your app's entry file (for Electron's render process) |
| 59 | +
|
| 60 | +│ └── ... |
| 61 | +
|
| 62 | +├── 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 | +
|
| 68 | +├── ... |
| 69 | +``` |
| 70 | + |
| 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: |
| 74 | + |
| 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. |
| 78 | + |
| 79 | +**Example:** |
| 80 | + |
| 81 | +`yarn build:electron [electron-builder options] --webpack [electron-webpack options]` |
| 82 | + |
| 83 | +### Electron Builder: |
| 84 | + |
| 85 | +To see avalible options, check out [Electron Builder Configuration Options](https://www.electron.build/configuration/configuration) |
| 86 | + |
| 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) |
| 110 | +
|
| 111 | +As per Electron Webpack's documentation, they can be applied: |
| 112 | +
|
| 113 | +> in `package.json` at `electronWebpack` or in a separate `electron-webpack.(json|json5|yml)`. |
| 114 | +
|
| 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`. |
| 116 | +
|
| 117 | +``` |
| 118 | +// vue.config.js |
| 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 | + }, |
| 125 | + pluginOptions: { |
| 126 | + electronBuilder: { |
| 127 | + webpackConfig: { |
| 128 | + // your electron-only webpack config |
| 129 | + } |
| 130 | + } |
| 131 | + } |
| 132 | +}; |
| 133 | +``` |
| 134 | +
|
| 135 | +#### Adding TypeScript Support: |
| 136 | +
|
| 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`). |
0 commit comments