If you feel like building a very simple multi-platform desktop app with your favourite tools: Electron, Vue.js and Parcel, this is your boilerplate.
I added the basic features needed to develop a quick and simple app. Other boilerplates add complexity that sometimes is not needed.
Using this boilerplate, I developed a HEIC to PNG/JPG converter.
-
If you want to use Electron and Vue.js heavily, I'd advise Electron-vue.
-
If you want to learn more about security or use a template with React, check this awesome template.
What you can find inside:
- Vuejs 3 with Typescript
- Parcel 2
- Communication between Electron and Vue.js
- Release your app to Github via Electron-Builder
What's missing:
- Translations - v2
- Electron auto-update - v2
- Tests - v2
- (Maybe) Typescript for the Electron files
Make sure you have Yarn installed and clone the repository git clone https://github.com/a133xz/electron-vuejs-parcel-boilerplate.git
yarnto install dependenciesyarn serveto run locally Vue.js + Electronyarn vue:serveto run locally only Vue.js using Parcelyarn build:localto build the project locally - by default is only compiling the mac appyarn patchto add a patch version and push the changes. More below.
Troubleshooting
If you've installled the dependencies with Yarn or NPM and it's still not working, reinstall Parcel:
yarn add -D parcel@next
Or when using NPM, run:
npm install -D parcel@next
To see how it works, download the latest app version from Github.
As you can see on the screenshot, there is:
- A message from a
dataatribute - A message from a Vuejs component
- A button that opens a dialog from Electron Native components
- An input to send a number to Electron and do a calculation
Find a great explanation here if you are new in Electron
We have 3 files to look at: main/index.js, main/preload.js and ElectronBridge.vue.
Electron gives you the posibility of preloading a script through webPreferences settings. Learn more on the official docs.
On preload, you'll find two functions:
receiveakaipcRenderer.on(eventName, callback): to listen to whatever we're sending fromindex.jssendakaipcRenderer.send(channel, data): to call the events onindex.js
Important: I whitelisted the events on preload.js
Events
Defined on main/index.js, for example:
ipcMain.on("showDialog", () => {
dialog.showMessageBoxSync({
type: "info",
message: "Hi I'm a dialog from Electron"
});
});ElectronBridge.vue
Usually called renderer.js. It has the functions to send and recieve data from Electron, so you'll need to set:
- the access to the Electron API:
window.electron - your method to call
showDialog - and finally if you need data from Electron, you'll need to set a listener, for example on the event
mounted
An interesting thing to highlight is that Electron and Parcel are both using the main path on the package.json. To avoid any problems, I made Parcel ignore the field as per the docs:
{
"main": "unrelated.js",
"targets": {
"main": false
}
}Divided into two main folders;
src/main for the Electron files:
src/main/index.jsis the entry point for our Electron app (your window settings and events)src/main/menu.jsthe settings for the menu of your appsrc/main/preload.jsthis is the file that expose to the main window events from Electron (data preparation / processing)
src/renderer for the Vue.js:
src/renderer/index.jsis the entry point for our Vue.js appsrc/renderer/App.vueis the entry point for the main App componentsrc/renderer/components/BasicComponent.vueis a component examplesrc/renderer/components/ElectronBridge.vueis a component that talks to Electron (event handling and displaying data)
And the stantard config files for ESLint or Typescript:
package.jsonis where you'll add your config settings for the Electron app
I'm using Github actions for the release, specifically action-electron-builder with a few tweaks; following samuelmeuli/action-electron-builder#9 I've updated the action to cache the build.
I divided the build-release process into two workflows:
build.ymlbuild the app everytime you create a PRrelease-electron-app.ymlbuild and release the app every time you tag your commit. This action will create a new draft of the release and then you'll have to publish it.
Right now it will only release the app for MacOS but you can change it anytime. Go to the workflow template and add/remove the platform you want:
os: [macos-latest] : os: [macos-latest, ubuntu-latest, windows-latest]
I added an example script to create a new release using npm version patch. A bit more of explanation when you run yarn patch:
npm version patchbump your your package.json version to the next one-m \"v%s\"creates a commit and tag with your version following this formatv*.*.*postversionscript will be run right after you bump the version to push your tag
You can learn more about it on the npm version docs.
When you want to create a new release, follow these steps:
- Update the version in your project's
package.jsonfile (e.g.1.2.3) - Commit that change (
git commit -am v1.2.3) - Tag your commit (
git tag v1.2.3). Make sure your tag name's format isv*.*.*. Your workflow will use this tag to detect when to create a release - Push your changes to GitHub (
git push && git push --tags)
This piece of documentation is from action-electron-builder, where you can learn more about creating a new release.
Issues and PRs are much appreciated. Please create a new branch and a PR to submit your suggestions.
If you've got questions, create an issue and I can answer it.
I used a combo of these projects to create the boilerplate:

