15 |
16 |
17 |
28 |
29 |
45 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Exeteres
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Electron Nuxt TypeScript
2 |
3 |
4 |
5 | ## Legacy version
6 |
7 | See [legacy](https://github.com/Exeteres/electron-nuxt-ts/tree/legacy) branch. Please note that this version uses the very old version of nuxt.
8 |
9 | ## Features
10 |
11 | - Everything is fully written in TypeScript, even configs
12 | - Class Component API
13 | - Simple and minimalist file structure
14 | - Vue + Nuxt devtools
15 | - Full nuxt server and compiler with hot reloading and preprocessors
16 | - Supporting native node addons out of the box
17 | - Powerful production build using electron-builder
18 |
19 | ## Installation
20 |
21 | Due to maintain difficulties, the installation via `vue-cli` has been removed. Now this repository is a template. Just clone it.
22 |
23 | ```shell
24 | git clone https://github.com/exeteres/electron-nuxt-ts
25 | ```
26 |
27 | ## FAQ
28 |
29 | - [How to use preprocessors?](https://nuxtjs.org/faq/pre-processors)
30 | - [How to add a Vuex store?](https://typescript.nuxtjs.org/cookbook/store)
31 | - [How to use Options API or Composition API?](https://typescript.nuxtjs.org/cookbook/components)
32 |
--------------------------------------------------------------------------------
/src/main/index.ts:
--------------------------------------------------------------------------------
1 | import { app, BrowserWindow } from "electron";
2 |
3 | import waitOn from "wait-on";
4 | import express from "express";
5 | import getPort from "get-port";
6 | import useragent from "express-useragent";
7 | import { resolve } from "path";
8 |
9 | let win: BrowserWindow;
10 |
11 | function loadContent(port = 3000) {
12 | win = new BrowserWindow({
13 | webPreferences: {
14 | nodeIntegration: true
15 | }
16 | });
17 | win.loadURL(`http://localhost:${port}`);
18 | }
19 |
20 | app.on("ready", async () => {
21 | if (process.env.NODE_ENV === "development") {
22 | // Importing dev dependencies
23 | const devtools = await import("electron-devtools-installer");
24 |
25 | // Installing devtools
26 | await devtools.default(devtools.VUEJS_DEVTOOLS);
27 |
28 | // Waiting for web server
29 | waitOn({ resources: [`http://localhost:3000`] }, loadContent);
30 | } else {
31 | const server = express();
32 | server.use(useragent.express());
33 |
34 | // Rejecting requests from browsers
35 | server.use((req, res, next) => {
36 | if (req.useragent.source.includes("Electron")) next();
37 | else res.end();
38 | });
39 |
40 | server.use(express.static(resolve(__dirname, "../renderer")));
41 |
42 | const port = await getPort();
43 | server.listen(port, "localhost", () => loadContent(port));
44 | }
45 | });
46 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "electron-nuxt-ts",
3 | "author": "Exeteres",
4 | "description": "Electron + Nuxt + Typescript",
5 | "version": "0.0.1",
6 | "main": "dist/main",
7 | "build": {
8 | "appId": "com.example.app",
9 | "files": [
10 | {
11 | "from": "dist",
12 | "to": "dist",
13 | "filter": [
14 | "main/**/*",
15 | "renderer/**/*"
16 | ]
17 | },
18 | {
19 | "from": ".",
20 | "filter": [
21 | "package.json"
22 | ]
23 | }
24 | ]
25 | },
26 | "scripts": {
27 | "build:main": "tsc -p tsconfig.main.json",
28 | "build:dist": "nuxt-ts generate && yarn build:main",
29 | "build:pack": "electron-builder",
30 | "build": "yarn build:dist && yarn build:pack",
31 | "dev": "yarn build:main && concurrently -k -n main,renderer -c blue,green \"cross-env NODE_ENV=development electron .\" \"nuxt-ts dev\""
32 | },
33 | "devDependencies": {
34 | "@nuxt/typescript-build": "^0.6.6",
35 | "@types/electron-devtools-installer": "^2.2.0",
36 | "@types/express": "^4.16.0",
37 | "@types/express-useragent": "^1.0.0",
38 | "@types/node": "^12.7.11",
39 | "@types/wait-on": "^4.0.0",
40 | "concurrently": "^5.2.0",
41 | "cross-env": "^7.0.2",
42 | "electron": "^8.5.2",
43 | "electron-builder": "^22.6.0",
44 | "electron-devtools-installer": "^3.0.0",
45 | "nuxt": "^2.12.2",
46 | "typescript": "~3.8.3"
47 | },
48 | "license": "MIT",
49 | "dependencies": {
50 | "@nuxt/typescript-runtime": "^0.4.6",
51 | "express": "^4.16.4",
52 | "express-useragent": "^1.0.13",
53 | "get-port": "^5.1.1",
54 | "nuxt-class-component": "^1.3.0",
55 | "wait-on": "^5.0.0"
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/renderer/components/Logo.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |