@tomjs/create-app 0.0.5 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/README.md +7 -5
  2. package/README.zh_CN.md +7 -30
  3. package/dist/index.mjs +4 -4
  4. package/package.json +5 -6
  5. package/template-config/.husky/commit-msg +5 -0
  6. package/template-config/.husky/common.sh +9 -0
  7. package/template-config/.husky/pre-commit +5 -0
  8. package/template-electron-react/.vscode/.debug.env +1 -0
  9. package/template-electron-react/.vscode/.debug.script.mjs +23 -0
  10. package/template-electron-react/.vscode/extensions.json +6 -0
  11. package/template-electron-react/.vscode/launch.json +53 -0
  12. package/template-electron-react/.vscode/settings.json +13 -0
  13. package/template-electron-react/.vscode/tasks.json +31 -0
  14. package/template-electron-react/README.md +28 -0
  15. package/template-electron-react/electron/electron-env.d.ts +11 -0
  16. package/template-electron-react/electron/main/index.ts +117 -0
  17. package/template-electron-react/electron/preload/index.ts +0 -0
  18. package/template-electron-react/index.html +15 -0
  19. package/template-electron-react/package.json +62 -0
  20. package/template-electron-react/public/img/icon.png +0 -0
  21. package/template-electron-react/public/vite.svg +1 -0
  22. package/template-electron-react/scripts/builder.ts +38 -0
  23. package/template-electron-react/scripts/constants.ts +16 -0
  24. package/template-electron-react/scripts/release.ts +41 -0
  25. package/template-electron-react/src/App.css +45 -0
  26. package/template-electron-react/src/App.tsx +40 -0
  27. package/template-electron-react/src/assets/electron.svg +10 -0
  28. package/template-electron-react/src/assets/react.svg +1 -0
  29. package/template-electron-react/src/index.css +69 -0
  30. package/template-electron-react/src/main.tsx +11 -0
  31. package/template-electron-react/src/vite-env.d.ts +1 -0
  32. package/template-electron-react/tsconfig.json +10 -0
  33. package/template-electron-react/tsconfig.node.json +7 -0
  34. package/template-electron-react/vite.config.ts +111 -0
  35. package/template-electron-vue/.vscode/.debug.env +1 -0
  36. package/template-electron-vue/.vscode/.debug.script.mjs +23 -0
  37. package/template-electron-vue/.vscode/extensions.json +6 -0
  38. package/template-electron-vue/.vscode/launch.json +53 -0
  39. package/template-electron-vue/.vscode/settings.json +13 -0
  40. package/template-electron-vue/.vscode/tasks.json +31 -0
  41. package/template-electron-vue/README.md +28 -0
  42. package/template-electron-vue/electron/electron-env.d.ts +11 -0
  43. package/template-electron-vue/electron/main/index.ts +117 -0
  44. package/template-electron-vue/electron/preload/index.ts +0 -0
  45. package/template-electron-vue/index.html +15 -0
  46. package/template-electron-vue/package.json +59 -0
  47. package/template-electron-vue/public/img/icon.png +0 -0
  48. package/template-electron-vue/public/vite.svg +1 -0
  49. package/template-electron-vue/scripts/builder.ts +38 -0
  50. package/template-electron-vue/scripts/constants.ts +16 -0
  51. package/template-electron-vue/scripts/release.ts +41 -0
  52. package/template-electron-vue/src/App.vue +43 -0
  53. package/template-electron-vue/src/assets/electron.svg +10 -0
  54. package/template-electron-vue/src/assets/vue.svg +1 -0
  55. package/template-electron-vue/src/components/HelloWorld.vue +37 -0
  56. package/template-electron-vue/src/main.ts +6 -0
  57. package/template-electron-vue/src/style.css +80 -0
  58. package/template-electron-vue/src/vite-env.d.ts +1 -0
  59. package/template-electron-vue/tsconfig.json +10 -0
  60. package/template-electron-vue/tsconfig.node.json +7 -0
  61. package/template-electron-vue/vite.config.ts +111 -0
  62. package/template-react/.eslintrc.cjs +7 -0
  63. package/template-react/README.md +5 -1
  64. package/template-react/_lintstagedrc.cjs +5 -0
  65. package/template-react/index.html +10 -12
  66. package/template-react/package.json +5 -4
  67. package/template-react/src/App.tsx +2 -2
  68. package/template-vue/.eslintrc.cjs +7 -0
  69. package/template-vue/README.md +4 -15
  70. package/template-vue/_lintstagedrc.cjs +6 -0
  71. package/template-vue/index.html +10 -12
  72. package/template-vue/package.json +4 -3
  73. /package/template-config/{.commitlintrc.js → .commitlintrc.cjs} +0 -0
  74. /package/template-config/{.prettierrc.js → .prettierrc.cjs} +0 -0
  75. /package/template-config/{.stylelintrc.js → .stylelintrc.cjs} +0 -0
  76. /package/{template-react/.eslintrc.js → template-electron-react/.eslintrc.cjs} +0 -0
  77. /package/{template-react/_lintstagedrc.js → template-electron-react/_lintstagedrc.cjs} +0 -0
  78. /package/{template-vue/.eslintrc.js → template-electron-vue/.eslintrc.cjs} +0 -0
  79. /package/{template-vue/_lintstagedrc.js → template-electron-vue/_lintstagedrc.cjs} +0 -0
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ![npm](https://img.shields.io/npm/v/%40tomjs/create-app) ![NPM](https://img.shields.io/npm/l/%40tomjs%2Fcreate-app) ![npm package minimized gzipped size (scoped version select exports)](https://img.shields.io/bundlejs/size/%40tomjs/create-app)
4
4
 
5
- Create a web application based on the tomjs configuration, recommended `node>=18`
5
+ Create a web application based on [vite](https://github.com/vitejs/vite) + [tomjs](https://github.com/tomgao365/tomjs), recommended `node>=18`
6
6
 
7
7
  **English** | [中文](./README.zh_CN.md)
8
8
 
@@ -33,31 +33,33 @@ You can also directly specify the project name, template, and module type.
33
33
  - Using `npm`
34
34
 
35
35
  ```bash
36
- npm create @tomjs/app@latest my-app -- --template vue --module
36
+ npm create @tomjs/app@latest my-app -- --template vue
37
37
  ```
38
38
 
39
39
  - Using `yarn`
40
40
 
41
41
  ```bash
42
- yarn create @tomjs/app my-app --template vue --module
42
+ yarn create @tomjs/app my-app --template vue
43
43
  ```
44
44
 
45
45
  - Using `pnpm`
46
46
 
47
47
  ```bash
48
- pnpm create @tomjs/app --template vue --module
48
+ pnpm create @tomjs/app --template vue
49
49
  ```
50
50
 
51
51
  Parameters:
52
52
 
53
53
  - `-t --template` : specify the template, optional values: `vue` , `react`
54
- - `-m --module` : `package.json` uses `type:"module"`, otherwise use `commonjs`
55
54
 
56
55
  Support templates:
57
56
 
58
57
  - vue
58
+ - electron-vue
59
59
  - react
60
+ - electron-react
60
61
 
61
62
  ## Reference project
62
63
 
63
64
  - [create-vite](https://github.com/vitejs/vite/tree/main/packages/create-vite)
65
+ - [electron-vite-vue](https://github.com/electron-vite/electron-vite-vue)
package/README.zh_CN.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ![npm](https://img.shields.io/npm/v/%40tomjs/create-app) ![NPM](https://img.shields.io/npm/l/%40tomjs%2Fcreate-app) ![npm package minimized gzipped size (scoped version select exports)](https://img.shields.io/bundlejs/size/%40tomjs/create-app)
4
4
 
5
- 创建基于 tomjs 配置的 web 应用,推荐 `node>=18`
5
+ 创建基于 [vite](https://github.com/vitejs/vite) + [tomjs](https://github.com/tomgao365/tomjs) web 应用,推荐 `node>=18`
6
6
 
7
7
  [English](./README.md) | **中文**
8
8
 
@@ -34,56 +34,33 @@ pnpm create @tomjs/app
34
34
 
35
35
  ```bash
36
36
  npm create @tomjs/app@latest
37
- npm create @tomjs/app@latest my-app -- --template vue --module
37
+ npm create @tomjs/app@latest my-app -- --template vue
38
38
  ```
39
39
 
40
40
  - 使用 `yarn`
41
41
 
42
42
  ```bash
43
- yarn create @tomjs/app my-app --template vue --module
43
+ yarn create @tomjs/app my-app --template vue
44
44
  ```
45
45
 
46
46
  - 使用 `pnpm`
47
47
 
48
48
  ```bash
49
- pnpm create @tomjs/app my-app --template vue --module
49
+ pnpm create @tomjs/app my-app --template vue
50
50
  ```
51
51
 
52
52
  参数说明:
53
53
 
54
54
  - `-t --template`:指定模板,可选值:`vue`、`react`
55
- - `-m --module`:`package.json` 使用 `type:"module"`,否则使用 `commonjs`
56
55
 
57
56
  支持模板:
58
57
 
59
58
  - vue
59
+ - electron-vue
60
60
  - react
61
-
62
- ## 项目配置
63
-
64
- 项目配置在 `package.json` 中,可配置项如下:
65
-
66
- ````json
67
- {
68
- "name": "my-app",
69
- "version": "0.0.1",
70
- "description": "",
71
- "main": "src/main.ts",
72
- }
73
-
74
- ## 项目结构
75
-
76
- ```bash
77
- .
78
- ├── README.md
79
- ├── package.json
80
- ├── src
81
- │ ├── App.vue
82
- │ ├── main.ts
83
- │ └── shims-vue.d.ts
84
- ├── tsconfig.json
61
+ - electron-react
85
62
 
86
63
  ## 参考项目
87
64
 
88
65
  - [create-vite](https://github.com/vitejs/vite/tree/main/packages/create-vite)
89
- ````
66
+ - [electron-vite-vue](https://github.com/electron-vite/electron-vite-vue)
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import s from"fs";import o from"path";import{fileURLToPath as U}from"url";import{cyan as J,green as W,red as E,reset as m}from"kolorist";import K from"minimist";import q from"prompts";import a from"fs";import k from"path";function _(e){return[["t","template"],["m","module"]].forEach(([t,n])=>{e[n]=e[n]??e[t]}),e}function A(e){let t=a.readdirSync(e);return t.length===0||t.length===1&&t[0]===".git"}function S(e){return e?.trim().replace(/\/+$/g,"")}function L(e,t){a.mkdirSync(t,{recursive:!0});for(let n of a.readdirSync(e)){let c=k.resolve(e,n),g=k.resolve(t,n);j(c,g)}}function j(e,t){a.statSync(e).isDirectory()?L(e,t):a.copyFileSync(e,t)}function D(e){if(a.existsSync(e))for(let t of a.readdirSync(e))t!==".git"&&a.rmSync(k.resolve(e,t),{recursive:!0,force:!0})}function w(e){return/^(?:@[a-z\d\-*~][a-z\d\-*._~]*\/)?[a-z\d\-~][a-z\d\-._~]*$/.test(e)}function $(e){return e.trim().toLowerCase().replace(/\s+/g,"-").replace(/^[._]/,"").replace(/[^a-z\d\-~]+/g,"-")}function b(e){if(!e)return;let n=e.split(" ")[0].split("/");return{name:n[0],version:n[1]}}var p=_(K(process.argv.slice(2),{string:["_"]})),h=process.cwd(),M=[{name:"vue",display:"Vue",color:W},{name:"react",display:"React",color:J}],C=M.map(e=>e.name),B={_gitignore:".gitignore","_lintstagedrc.js":".lintstagedrc.js"},x="my-app";async function G(){let e=S(p._[0]),t=p.template||p.t,n=e||x,c=()=>n==="."?o.basename(o.resolve()):n,g=await q([{type:e?null:"text",name:"projectName",message:m("Project name:"),initial:x,onState:r=>{n=S(r.value)||x}},{type:()=>!s.existsSync(n)||A(n)?null:"toggle",name:"overwrite",message:()=>(n==="."?"Current directory":`Target directory "${n}"`)+" is not empty. Remove existing files and continue?",initial:!1,active:"yes",inactive:"no"},{type:(r,{overwrite:l})=>{if(l===!1)throw new Error(E("\u2716")+" Operation cancelled");return null},name:"overwriteChecker"},{type:()=>w(c())?null:"text",name:"packageName",message:m("Package name:"),initial:()=>$(c()),validate:r=>w(r)||"Invalid package.json name"},{type:t&&C.includes(t)?null:"select",name:"framework",message:typeof t=="string"&&!C.includes(t)?m(`"${t}" isn't a valid template. Please choose from below: `):m("Select a framework:"),initial:0,choices:M.map(r=>{let l=r.color;return{title:l(r.display||r.name),value:r}})},{type:()=>p.module!==void 0?null:"toggle",name:"isModuleType",message:m("Is it set to module type?"),initial:!1,active:"yes",inactive:"no"}],{onCancel:()=>{throw console.log(E("\u2716")+" Operation cancelled"),new Error}}),{framework:R,overwrite:z,packageName:O}=g,i=o.join(h,n);z?D(i):s.existsSync(i)||s.mkdirSync(i,{recursive:!0}),console.log(`
3
- Scaffolding project in ${i}...`);let V=R?.name||t,F=g.isModuleType??p.module,N=r=>o.join(U(import.meta.url),"../..",`template-${r}`),P=N(V);[P,N("config")].forEach(r=>{let l=s.readdirSync(r);for(let v of l){let u=B[v]??v;F&&u.endsWith("rc.js")&&(u=u.replace(".js",".cjs"));let I=o.join(i,u);j(o.join(r,v),I)}});let f=JSON.parse(s.readFileSync(o.join(P,"package.json"),"utf-8"));f.name=O||c(),F?f.type="module":delete f.type,s.writeFileSync(o.join(i,"package.json"),JSON.stringify(f,null,2)+`
4
- `);let T=b(process.env.npm_config_user_agent),d=T?T.name:"npm",y=o.relative(h,i);switch(console.log(`
2
+ import c from"fs";import a from"path";import{fileURLToPath as J}from"url";import{blue as A,cyan as K,green as q,red as D,reset as p,yellow as T}from"kolorist";import B from"minimist";import G from"prompts";import s from"fs";import d from"path";function P(e){return[["t","template"]].forEach(([t,n])=>{e[n]=e[n]??e[t]}),e}function _(e){let t=s.readdirSync(e);return t.length===0||t.length===1&&t[0]===".git"}function y(e){return e?.trim().replace(/\/+$/g,"")}function I(e,t){s.mkdirSync(t,{recursive:!0});for(let n of s.readdirSync(e)){let l=d.resolve(e,n),g=d.resolve(t,n);v(l,g)}}function v(e,t){s.statSync(e).isDirectory()?I(e,t):s.copyFileSync(e,t)}function b(e){if(s.existsSync(e))for(let t of s.readdirSync(e))t!==".git"&&s.rmSync(d.resolve(e,t),{recursive:!0,force:!0})}function k(e){return/^(?:@[a-z\d\-*~][a-z\d\-*._~]*\/)?[a-z\d\-~][a-z\d\-._~]*$/.test(e)}function C(e){return e.trim().toLowerCase().replace(/\s+/g,"-").replace(/^[._]/,"").replace(/[^a-z\d\-~]+/g,"-")}function E(e){if(!e)return;let n=e.split(" ")[0].split("/");return{name:n[0],version:n[1]}}var w=P(B(process.argv.slice(2),{string:["_"]})),S=process.cwd(),R=[{name:"vue",display:"Vue",color:q,variants:[{name:"vue",display:"Web",color:A},{name:"electron-vue",display:"Electron",color:T}]},{name:"react",display:"React",color:K,variants:[{name:"react",display:"Web",color:A},{name:"electron-react",display:"Electron",color:T}]}],$=R.map(e=>e.variants&&e.variants.map(t=>t.name)||[e.name]).reduce((e,t)=>e.concat(t),[]),H={_gitignore:".gitignore","_lintstagedrc.cjs":".lintstagedrc.cjs"},F="my-app";async function Q(){let e=y(w._[0]),t=w.template||w.t,n=e||F,l=()=>n==="."?a.basename(a.resolve()):n,g={};g=await G([{type:e?null:"text",name:"projectName",message:p("Project name:"),initial:F,onState:r=>{n=y(r.value)||F}},{type:()=>!c.existsSync(n)||_(n)?null:"toggle",name:"overwrite",message:()=>(n==="."?"Current directory":`Target directory "${n}"`)+" is not empty. Remove existing files and continue?",initial:!1,active:"yes",inactive:"no"},{type:(r,{overwrite:o})=>{if(o===!1)throw console.log(D("\u2716")+" Operation cancelled"),new Error;return null},name:"overwriteChecker"},{type:()=>k(l())?null:"text",name:"packageName",message:p("Package name:"),initial:()=>C(l()),validate:r=>k(r)||"Invalid package.json name"},{type:t&&$.includes(t)?null:"select",name:"framework",message:typeof t=="string"&&!$.includes(t)?p(`"${t}" isn't a valid template. Please choose from below: `):p("Select a framework:"),initial:0,choices:R.map(r=>{let o=r.color;return{title:o(r.display||r.name),value:r}})},{type:r=>r&&r.variants?"select":null,name:"variant",message:p("Select a variant:"),choices:r=>r.variants.map(o=>{let m=o.color;return{title:m(o.display||o.name),value:o.name}})}],{onCancel:()=>{throw console.log(D("\u2716")+" Operation cancelled"),new Error}});let{framework:V,overwrite:z,packageName:O,variant:L}=g,i=a.join(S,n);z?b(i):c.existsSync(i)||c.mkdirSync(i,{recursive:!0}),console.log(`
3
+ Scaffolding project in ${i}...`);let M=L||V?.name||t||"",h=r=>a.join(J(import.meta.url),"../..",`template-${r}`),j=h(M);[j,h("config")].forEach(r=>{let o=c.readdirSync(r);for(let m of o){let U=H[m]??m,W=a.join(i,U);v(a.join(r,m),W)}});let x=JSON.parse(c.readFileSync(a.join(j,"package.json"),"utf-8"));x.name=O||l(),c.writeFileSync(a.join(i,"package.json"),JSON.stringify(x,null,2)+`
4
+ `);let N=E(process.env.npm_config_user_agent),u=N?N.name:"npm",f=a.relative(S,i);switch(console.log(`
5
5
  Done. Now run:
6
- `),i!==h&&console.log(` cd ${y.includes(" ")?`"${y}"`:y}`),d){case"yarn":console.log(" yarn"),console.log(" yarn dev");break;default:console.log(` ${d} install`),console.log(` ${d} run dev`);break}}G().catch(()=>{});
6
+ `),i!==S&&console.log(` cd ${f.includes(" ")?`"${f}"`:f}`),u){case"yarn":console.log(" yarn"),console.log(" yarn dev");break;default:console.log(` ${u} install`),console.log(` ${u} run dev`);break}}Q().catch(e=>{e.message&&console.error(e)});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomjs/create-app",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "create tomjs web app",
5
5
  "keywords": [
6
6
  "tomjs",
@@ -43,9 +43,9 @@
43
43
  "@tomjs/commitlint": "^2.0.3",
44
44
  "@tomjs/eslint": "^1.0.7",
45
45
  "@tomjs/prettier": "^1.0.5",
46
- "@tomjs/tsconfig": "^1.0.6",
46
+ "@tomjs/tsconfig": "^1.0.7",
47
47
  "@types/minimist": "^1.2.5",
48
- "@types/node": "^18.18.9",
48
+ "@types/node": "^18.18.10",
49
49
  "@types/prompts": "^2.4.8",
50
50
  "eslint": "^8.53.0",
51
51
  "husky": "^8.0.3",
@@ -53,7 +53,7 @@
53
53
  "np": "^8.0.4",
54
54
  "npm-run-all": "^4.1.5",
55
55
  "prettier": "^3.1.0",
56
- "tsup": "^7.2.0",
56
+ "tsup": "^7.3.0",
57
57
  "typescript": "^5.2.2"
58
58
  },
59
59
  "scripts": {
@@ -61,7 +61,6 @@
61
61
  "build": "tsup --minify",
62
62
  "lint": "run-s lint:eslint lint:prettier",
63
63
  "lint:eslint": "eslint \"src/**/*.{js,cjs,ts}\" *.{js,cjs,ts} --fix --cache",
64
- "lint:prettier": "prettier --write \"src/**/*.{js,cjs,ts,json,md}\" *.{js,cjs,ts,json,md}",
65
- "release": "np --any-branch --no-yarn --yolo --no-publish --message \"chore: release v%s\""
64
+ "lint:prettier": "prettier --write \"src/**/*.{js,cjs,ts,json,md}\" *.{js,cjs,ts,json,md}"
66
65
  }
67
66
  }
@@ -0,0 +1,5 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+ . "$(dirname "$0")/common.sh"
4
+
5
+ pnpm commitlint --edit $1
@@ -0,0 +1,9 @@
1
+ #!/bin/sh
2
+ command_exists () {
3
+ command -v "$1" >/dev/null 2>&1
4
+ }
5
+
6
+ # Workaround for Windows 10, Git Bash and Yarn
7
+ if command_exists winpty && test -t 1; then
8
+ exec < /dev/tty
9
+ fi
@@ -0,0 +1,5 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+ . "$(dirname "$0")/common.sh"
4
+
5
+ pnpm lint-staged
@@ -0,0 +1 @@
1
+ VITE_DEV_SERVER_URL=http://127.0.0.1:6888/
@@ -0,0 +1,23 @@
1
+ import fs from 'node:fs'
2
+ import path from 'node:path'
3
+ import { fileURLToPath } from 'node:url'
4
+ import { createRequire } from 'node:module'
5
+ import { spawn } from 'node:child_process'
6
+
7
+ const pkg = createRequire(import.meta.url)('../package.json')
8
+ const __dirname = path.dirname(fileURLToPath(import.meta.url))
9
+
10
+ // write .debug.env
11
+ const envContent = Object.entries(pkg.debug.env).map(([key, val]) => `${key}=${val}`)
12
+ fs.writeFileSync(path.join(__dirname, '.debug.env'), envContent.join('\n'))
13
+
14
+ // bootstrap
15
+ spawn(
16
+ // TODO: terminate `npm run dev` when Debug exits.
17
+ process.platform === 'win32' ? 'npm.cmd' : 'npm',
18
+ ['run', 'dev'],
19
+ {
20
+ stdio: 'inherit',
21
+ env: Object.assign(process.env, { VSCODE_DEBUG: 'true' }),
22
+ },
23
+ )
@@ -0,0 +1,6 @@
1
+ {
2
+ "recommendations": [
3
+ "Vue.volar",
4
+ "Vue.vscode-typescript-vue-plugin"
5
+ ]
6
+ }
@@ -0,0 +1,53 @@
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "compounds": [
7
+ {
8
+ "name": "Debug App",
9
+ "preLaunchTask": "Before Debug",
10
+ "configurations": [
11
+ "Debug Main Process",
12
+ "Debug Renderer Process"
13
+ ],
14
+ "presentation": {
15
+ "hidden": false,
16
+ "group": "",
17
+ "order": 1
18
+ },
19
+ "stopAll": true
20
+ }
21
+ ],
22
+ "configurations": [
23
+ {
24
+ "name": "Debug Main Process",
25
+ "type": "node",
26
+ "request": "launch",
27
+ "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
28
+ "windows": {
29
+ "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd"
30
+ },
31
+ "runtimeArgs": [
32
+ "--remote-debugging-port=9229",
33
+ "."
34
+ ],
35
+ "envFile": "${workspaceFolder}/.vscode/.debug.env",
36
+ "console": "integratedTerminal"
37
+ },
38
+ {
39
+ "name": "Debug Renderer Process",
40
+ "port": 9229,
41
+ "request": "attach",
42
+ "type": "chrome",
43
+ "timeout": 60000,
44
+ "skipFiles": [
45
+ "<node_internals>/**",
46
+ "${workspaceRoot}/node_modules/**",
47
+ "${workspaceRoot}/dist-electron/**",
48
+ // Skip files in host(VITE_DEV_SERVER_URL)
49
+ "http://127.0.0.1:6888/**"
50
+ ]
51
+ },
52
+ ]
53
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "typescript.tsdk": "node_modules/typescript/lib",
3
+ "typescript.tsc.autoDetect": "off",
4
+ "json.schemas": [
5
+ {
6
+ "fileMatch": [
7
+ "/*electron-builder.json5",
8
+ "/*electron-builder.json"
9
+ ],
10
+ "url": "https://json.schemastore.org/electron-builder"
11
+ }
12
+ ]
13
+ }
@@ -0,0 +1,31 @@
1
+ {
2
+ // See https://go.microsoft.com/fwlink/?LinkId=733558
3
+ // for the documentation about the tasks.json format
4
+ "version": "2.0.0",
5
+ "tasks": [
6
+ {
7
+ "label": "Before Debug",
8
+ "type": "shell",
9
+ "command": "node .vscode/.debug.script.mjs",
10
+ "isBackground": true,
11
+ "problemMatcher": {
12
+ "owner": "typescript",
13
+ "fileLocation": "relative",
14
+ "pattern": {
15
+ // TODO: correct "regexp"
16
+ "regexp": "^([a-zA-Z]\\:\/?([\\w\\-]\/?)+\\.\\w+):(\\d+):(\\d+): (ERROR|WARNING)\\: (.*)$",
17
+ "file": 1,
18
+ "line": 3,
19
+ "column": 4,
20
+ "code": 5,
21
+ "message": 6
22
+ },
23
+ "background": {
24
+ "activeOnStart": true,
25
+ "beginsPattern": "^.*VITE v.* ready in \\d* ms.*$",
26
+ "endsPattern": "^.*\\[startup\\] Electron App.*$"
27
+ }
28
+ }
29
+ }
30
+ ]
31
+ }
@@ -0,0 +1,28 @@
1
+ # electron-react
2
+
3
+ vite + electron + react
4
+
5
+ ## Description
6
+
7
+ - source code
8
+
9
+ ```
10
+ ├── electron
11
+ │ ├── main > Electron-Main
12
+ │ ├── payload > Electron-payload
13
+ ├── src > Electron-Renderer
14
+ ```
15
+
16
+ - output
17
+
18
+ ```
19
+ ├─┬ dist
20
+ │ ├── main.js > Electron-Main
21
+ │ ├── preload.js > Preload-Scripts
22
+ │ ├─┬ render > Electron-Renderer
23
+ │ │ └── index.html
24
+ ```
25
+
26
+ ## Reference project
27
+
28
+ - [electron-vite-react](https://github.com/electron-vite/electron-vite-react)
@@ -0,0 +1,11 @@
1
+ /// <reference types="vite-plugin-electron/electron-env" />
2
+
3
+ declare namespace NodeJS {
4
+ interface ProcessEnv {
5
+ VSCODE_DEBUG?: 'true';
6
+ DIST_ELECTRON: string;
7
+ DIST: string;
8
+ /** /dist/ or /public/ */
9
+ VITE_PUBLIC: string;
10
+ }
11
+ }
@@ -0,0 +1,117 @@
1
+ import { release } from 'node:os';
2
+ import { join } from 'node:path';
3
+ import { app, BrowserWindow, ipcMain, shell } from 'electron';
4
+
5
+ // The built directory structure
6
+ //
7
+ // ├─┬ dist
8
+ // │ ├── main.js > Electron-Main
9
+ // │ ├── preload.js > Preload-Scripts
10
+ // │ ├─┬ render > Electron-Renderer
11
+ // │ │ └── index.html
12
+ //
13
+ process.env.DIST_ELECTRON = __dirname;
14
+ process.env.DIST = join(process.env.DIST_ELECTRON, 'render');
15
+ process.env.VITE_PUBLIC = process.env.VITE_DEV_SERVER_URL
16
+ ? join(process.env.DIST_ELECTRON, '../public')
17
+ : process.env.DIST;
18
+
19
+ // Disable GPU Acceleration for Windows 7
20
+ if (release().startsWith('6.1')) app.disableHardwareAcceleration();
21
+
22
+ // Set application name for Windows 10+ notifications
23
+ if (process.platform === 'win32') app.setAppUserModelId(app.getName());
24
+
25
+ if (!app.requestSingleInstanceLock()) {
26
+ app.quit();
27
+ process.exit(0);
28
+ }
29
+
30
+ // Remove electron security warnings
31
+ // This warning only shows in development mode
32
+ // Read more on https://www.electronjs.org/docs/latest/tutorial/security
33
+ // process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true'
34
+
35
+ let win: BrowserWindow | null = null;
36
+ // Here, you can also use other preload
37
+ const preload = join(__dirname, './preload.js');
38
+ const url = process.env.VITE_DEV_SERVER_URL as string;
39
+ const indexHtml = join(process.env.DIST, 'index.html');
40
+
41
+ async function createWindow() {
42
+ win = new BrowserWindow({
43
+ title: 'Main window',
44
+ width: 800,
45
+ height: 700,
46
+ webPreferences: {
47
+ preload,
48
+ // Warning: Enable nodeIntegration and disable contextIsolation is not secure in production
49
+ // Consider using contextBridge.exposeInMainWorld
50
+ // Read more on https://www.electronjs.org/docs/latest/tutorial/context-isolation
51
+ nodeIntegration: true,
52
+ contextIsolation: false,
53
+ },
54
+ });
55
+
56
+ if (process.env.VITE_DEV_SERVER_URL) {
57
+ // electron-vite-vue#298
58
+ win.loadURL(url);
59
+ // Open devTool if the app is not packaged
60
+ // win.webContents.openDevTools();
61
+ } else {
62
+ win.loadFile(indexHtml);
63
+ }
64
+
65
+ // Test actively push message to the Electron-Renderer
66
+ win.webContents.on('did-finish-load', () => {
67
+ win?.webContents.send('main-process-message', new Date().toLocaleString());
68
+ });
69
+
70
+ // Make all links open with the browser, not with the application
71
+ win.webContents.setWindowOpenHandler(({ url }) => {
72
+ if (url.startsWith('https:')) shell.openExternal(url);
73
+ return { action: 'deny' };
74
+ });
75
+ // win.webContents.on('will-navigate', (event, url) => { }) #344
76
+ }
77
+
78
+ app.whenReady().then(createWindow);
79
+
80
+ app.on('window-all-closed', () => {
81
+ win = null;
82
+ if (process.platform !== 'darwin') app.quit();
83
+ });
84
+
85
+ app.on('second-instance', () => {
86
+ if (win) {
87
+ // Focus on the main window if the user tried to open another
88
+ if (win.isMinimized()) win.restore();
89
+ win.focus();
90
+ }
91
+ });
92
+
93
+ app.on('activate', () => {
94
+ const allWindows = BrowserWindow.getAllWindows();
95
+ if (allWindows.length) {
96
+ allWindows[0].focus();
97
+ } else {
98
+ createWindow();
99
+ }
100
+ });
101
+
102
+ // New window example arg: new windows url
103
+ ipcMain.handle('open-win', (_, arg) => {
104
+ const childWindow = new BrowserWindow({
105
+ webPreferences: {
106
+ preload,
107
+ nodeIntegration: true,
108
+ contextIsolation: false,
109
+ },
110
+ });
111
+
112
+ if (process.env.VITE_DEV_SERVER_URL) {
113
+ childWindow.loadURL(`${url}#${arg}`);
114
+ } else {
115
+ childWindow.loadFile(indexHtml, { hash: arg });
116
+ }
117
+ });
@@ -0,0 +1,15 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <link rel="icon" type="image/svg+xml" href="/vite.svg" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
8
+ <title>Vite + Electron + React + TS</title>
9
+ </head>
10
+
11
+ <body>
12
+ <div id="root"></div>
13
+ <script type="module" src="/src/main.tsx"></script>
14
+ </body>
15
+ </html>
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "electron-app",
3
+ "version": "0.0.0",
4
+ "description": "vite + electron + vue",
5
+ "type": "module",
6
+ "engines": {
7
+ "node": ">=18"
8
+ },
9
+ "debug": {
10
+ "env": {
11
+ "VITE_DEV_SERVER_URL": "http://127.0.0.1:6888/"
12
+ }
13
+ },
14
+ "main": "dist/main.js",
15
+ "scripts": {
16
+ "dev": "vite",
17
+ "build": "npm run clean && vue-tsc --noEmit && vite build",
18
+ "releaseOnly": "tsx ./scripts/release.ts",
19
+ "release": "npm run build && npm run releaseOnly",
20
+ "clean": "rimraf ./dist",
21
+ "preview": "vite preview",
22
+ "lint": "run-s lint:eslint lint:stylelint lint:prettier",
23
+ "lint:eslint": "eslint \"src/**/*.{ts,tsx,vue}\" *.{js,cjs,ts} --fix --cache",
24
+ "lint:stylelint": "stylelint \"src/**/*.{css,scss,less,vue,html}\" --fix --cache",
25
+ "lint:prettier": "prettier --write .",
26
+ "prepare": "husky install"
27
+ },
28
+ "dependencies": {
29
+ "react": "^18.2.0",
30
+ "react-dom": "^18.2.0"
31
+ },
32
+ "devDependencies": {
33
+ "@commitlint/cli": "^18.4.2",
34
+ "@tomjs/commitlint": "^2.0.3",
35
+ "@tomjs/eslint": "^1.0.7",
36
+ "@tomjs/prettier": "^1.0.5",
37
+ "@tomjs/stylelint": "^1.0.5",
38
+ "@tomjs/tsconfig": "^1.0.7",
39
+ "@types/node": "^18.18.10",
40
+ "@types/react": "^18.2.37",
41
+ "@types/react-dom": "^18.2.15",
42
+ "@types/shelljs": "^0.8.15",
43
+ "@vitejs/plugin-react-swc": "^3.5.0",
44
+ "electron": "^27.1.0",
45
+ "electron-builder": "^24.6.4",
46
+ "eslint": "^8.53.0",
47
+ "husky": "^8.0.3",
48
+ "lint-staged": "^15.1.0",
49
+ "npm-run-all": "^4.1.5",
50
+ "prettier": "^3.1.0",
51
+ "rimraf": "^5.0.5",
52
+ "shelljs": "^0.8.5",
53
+ "stylelint": "^15.11.0",
54
+ "tree-kill": "^1.2.2",
55
+ "tsx": "^4.1.3",
56
+ "typescript": "^5.2.2",
57
+ "vite": "^5.0.0",
58
+ "vite-plugin-electron": "^0.15.4",
59
+ "vite-plugin-electron-renderer": "^0.14.5",
60
+ "vue-tsc": "^1.8.22"
61
+ }
62
+ }
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
@@ -0,0 +1,38 @@
1
+ import type { Configuration } from 'electron-builder';
2
+ import pkg from '../package.json';
3
+
4
+ /**
5
+ * @see https://www.electron.build/configuration/configuration
6
+ */
7
+ export default {
8
+ appId: 'com.xxx.app',
9
+ productName: 'App',
10
+ directories: {
11
+ output: `build/${pkg.version}`,
12
+ app: 'dist',
13
+ },
14
+ files: ['main.js', 'preload.js', 'render'],
15
+ icon: 'public/img/icon.png',
16
+ artifactName: '${productName}-${version}-${os}-${arch}.${ext}',
17
+ electronLanguages: ['zh-CN', 'en-US'],
18
+ win: {
19
+ target: [
20
+ {
21
+ target: 'nsis',
22
+ arch: ['x64'],
23
+ },
24
+ ],
25
+ },
26
+ mac: {
27
+ target: ['dmg'],
28
+ },
29
+ linux: {
30
+ target: ['AppImage'],
31
+ },
32
+ nsis: {
33
+ oneClick: false,
34
+ perMachine: false,
35
+ allowToChangeInstallationDirectory: true,
36
+ deleteAppDataOnUninstall: false,
37
+ },
38
+ } as Configuration;
@@ -0,0 +1,16 @@
1
+ import path from 'node:path';
2
+
3
+ /**
4
+ * 项目根路径
5
+ */
6
+ export const ROOT_PATH = path.join(__dirname, '../');
7
+
8
+ /**
9
+ * 生成代码目录
10
+ */
11
+ export const DIST_PATH = path.join(ROOT_PATH, '../dist');
12
+
13
+ /**
14
+ * electron 依赖模块
15
+ */
16
+ export const ELECTRON_DEPENDENCIES: string[] = [];