Skip to content

Commit e4e6249

Browse files
committed
docs: add vue3 framework-integration
1 parent 9be2591 commit e4e6249

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed

guides/framework-integration/vue-3.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
---
2+
description: How to create an Electron app with Vue 3 and Electron Forge
3+
---
4+
5+
# Vue 3
6+
7+
Adding Vue 3 support to a basic Electron Forge template doesn't require a complicated boilerplate to get started.
8+
9+
### Create the app
10+
11+
Create a standard Electron per the [Getting Started](../../#the-basics) guide.
12+
13+
### Add the Vue 3 dependency
14+
15+
Add the Vue 3 package to your `dependencies`:
16+
17+
{% tabs %}
18+
{% tab title="NPM" %}
19+
20+
```bash
21+
npm install --save vue
22+
```
23+
24+
{% endtab %}
25+
26+
{% tab title="Yarn" %}
27+
28+
```bash
29+
yarn add vue
30+
```
31+
32+
{% endtab %}
33+
{% endtabs %}
34+
35+
### Integrate Vue 3 code
36+
37+
You should now be able to start writing and using Vue 3 components in your Electron app. The following is a very minimal example of how to start to add Vue 3 code:
38+
39+
{% tabs %}
40+
{% tab title="src/index.html" %}
41+
Add the following before the closing `</body>` tag:
42+
43+
```markup
44+
<div id="app">
45+
{{ message }}
46+
</div>
47+
<script type="module" src="./renderer.js"></script>
48+
```
49+
50+
{% endtab %}
51+
52+
{% tab title="src/renderer.js" %}
53+
54+
```javascript
55+
import { createApp } from "../node_modules/vue/dist/vue.esm-browser.js";
56+
57+
createApp({
58+
data() {
59+
return {
60+
message: 2,
61+
};
62+
},
63+
}).mount("#app");
64+
```
65+
66+
{% endtab %}
67+
{% endtabs %}
68+
69+
### Alternative: Using Single File Components <a href="#using-single-file-components" id="using-single-file-components"></a>
70+
71+
For advanced use cases such as single file components, it's recommended to use the [Webpack plugin](../../config/plugins/webpack.md) so that the components get built correctly. You'll also need to add the appropriate Vue loader/compiler packages to the app's `devDependencies`.
72+
73+
Create the app with the [Webpack template](../../templates/webpack-template.md) or the [TypeScript + Webpack template](../../templates/typescript-+-webpack-template.md). Add the following packages to your `devDependencies` so that the single file components get compiled and loaded correctly:
74+
75+
{% tabs %}
76+
{% tab title="NPM" %}
77+
78+
```
79+
npm install --save-dev vue-loader
80+
```
81+
82+
{% endtab %}
83+
84+
{% tab title="Yarn" %}
85+
86+
```bash
87+
yarn add --dev vue-loader
88+
```
89+
90+
{% endtab %}
91+
{% endtabs %}
92+
93+
Setting up the [`vue-loader` Webpack module](https://vue-loader.vuejs.org/guide/#webpack-configuration) is left as an exercise for the reader _(hint: `vue-loader` Webpack config should ideally go in the renderer configuration only)_.
94+
95+
Add the Vue 3 package to your `dependencies`:
96+
97+
{% tabs %}
98+
{% tab title="NPM" %}
99+
100+
```bash
101+
npm install --save vue
102+
```
103+
104+
{% endtab %}
105+
106+
{% tab title="Yarn" %}
107+
108+
```bash
109+
yarn add vue
110+
```
111+
112+
{% endtab %}
113+
{% endtabs %}
114+
115+
You should now be able to add single file components to your app, the same as you would for a "regular" web app.

0 commit comments

Comments
 (0)