@tomjs/create-app 1.6.1 → 2.0.0
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.
- package/README.md +1 -1
- package/README.zh_CN.md +1 -1
- package/dist/index.js +10 -22
- package/package.json +48 -48
- package/templates/{base/core → config/base}/.editorconfig +0 -4
- package/templates/config/base/.vscode/settings.json +50 -0
- package/templates/{base/core/_gitignore → config/base/_.gitignore} +1 -3
- package/templates/config/base/_commitlint.config.mjs +3 -0
- package/templates/config/base/_eslint.config.mjs +8 -0
- package/templates/config/base/lint-staged.config.mjs +3 -0
- package/templates/config/base/package.json +24 -0
- package/templates/config/base/pnpm-workspace.yaml +3 -0
- package/templates/config/base/simple-git-hooks.mjs +4 -0
- package/templates/{vscode → config/public}/LICENSE +1 -1
- package/templates/config/public/README.md +20 -0
- package/templates/config/public/README.zh_CN.md +20 -0
- package/templates/config/public/package.json +10 -0
- package/templates/config/style/lint-staged.config.mjs +7 -0
- package/templates/config/style/package.json +12 -0
- package/templates/config/style/stylelint.config.mjs +3 -0
- package/templates/{base/electron → electron-react}/.vscode/launch.json +23 -3
- package/templates/electron-react/.vscode/tasks.json +67 -0
- package/templates/electron-react/README.md +1 -1
- package/templates/electron-react/_eslint.config.mjs +8 -0
- package/templates/electron-react/electron/main/index.ts +71 -40
- package/templates/electron-react/electron/preload/index.ts +4 -0
- package/templates/electron-react/index.html +1 -2
- package/templates/electron-react/package.json +35 -1
- package/templates/electron-react/pnpm-workspace.yaml +6 -0
- package/templates/electron-react/src/App.css +6 -2
- package/templates/electron-react/src/App.tsx +12 -5
- package/templates/electron-react/src/index.css +14 -9
- package/templates/electron-react/tsconfig.json +9 -0
- package/templates/{base/electron → electron-react}/tsconfig.node.json +1 -1
- package/templates/electron-react/vite.config.ts +8 -21
- package/templates/electron-vue/.vscode/launch.json +48 -0
- package/templates/electron-vue/.vscode/tasks.json +67 -0
- package/templates/electron-vue/README.md +1 -1
- package/templates/electron-vue/_eslint.config.mjs +8 -0
- package/templates/electron-vue/electron/env.d.ts +1 -0
- package/templates/electron-vue/electron/main/index.ts +46 -30
- package/templates/electron-vue/electron/preload/index.ts +4 -0
- package/templates/electron-vue/index.html +1 -2
- package/templates/electron-vue/package.json +31 -2
- package/templates/electron-vue/pnpm-workspace.yaml +5 -0
- package/templates/electron-vue/src/App.vue +1 -1
- package/templates/electron-vue/src/style.css +15 -10
- package/templates/electron-vue/tsconfig.json +5 -0
- package/templates/electron-vue/tsconfig.node.json +7 -0
- package/templates/electron-vue/vite.config.ts +2 -20
- package/templates/{node-cli-legacy → node-base}/.vscode/launch.json +3 -6
- package/templates/node-base/package.json +15 -0
- package/templates/node-base/src/index.ts +5 -0
- package/templates/{node-cli-legacy → node-base}/tsconfig.json +1 -1
- package/templates/node-cli/.vscode/i18n-ally-custom-framework.yml +35 -0
- package/templates/node-cli/.vscode/launch.json +3 -6
- package/templates/node-cli/.vscode/settings.json +56 -0
- package/templates/node-cli/_.gitignore +59 -0
- package/templates/node-cli/locales/en-US.json +11 -0
- package/templates/node-cli/locales/zh-Hans.json +11 -0
- package/templates/node-cli/locales/zh-Hant.json +11 -0
- package/templates/node-cli/package.json +18 -20
- package/templates/node-cli/src/app.ts +19 -0
- package/templates/node-cli/src/config.ts +2 -2
- package/templates/node-cli/src/index.ts +77 -1
- package/templates/node-cli/src/types.ts +5 -1
- package/templates/node-cli/src/utils/exec.ts +68 -0
- package/templates/node-cli/src/utils/index.ts +3 -0
- package/templates/node-cli/src/utils/lang.ts +104 -0
- package/templates/node-cli/src/utils/util.ts +20 -0
- package/templates/node-cli/tsconfig.json +2 -2
- package/templates/node-cli/{tsup.config.ts → tsdown.config.ts} +3 -4
- package/templates/node-vite/examples/react/README.md +1 -0
- package/templates/node-vite/examples/react/_eslint.config.mjs +6 -0
- package/templates/{react → node-vite/examples/react}/index.html +1 -2
- package/templates/node-vite/examples/react/package.json +27 -0
- package/templates/{react → node-vite/examples/react}/src/App.css +5 -2
- package/templates/{react → node-vite/examples/react}/src/App.tsx +8 -9
- package/templates/{react → node-vite/examples/react}/src/index.css +15 -11
- package/templates/node-vite/examples/react/src/main.tsx +10 -0
- package/templates/node-vite/examples/react/tsconfig.json +5 -0
- package/templates/node-vite/examples/react/vite.config.ts +14 -0
- package/templates/node-vite/examples/vue/README.md +1 -0
- package/templates/node-vite/examples/vue/_eslint.config.mjs +6 -0
- package/templates/{vue → node-vite/examples/vue}/index.html +1 -2
- package/templates/node-vite/examples/vue/package.json +22 -0
- package/templates/{vue → node-vite/examples/vue}/src/App.vue +3 -3
- package/templates/node-vite/examples/vue/src/components/HelloWorld.vue +19 -0
- package/templates/{vue → node-vite/examples/vue}/src/main.ts +0 -1
- package/templates/{vue → node-vite/examples/vue}/src/style.css +16 -12
- package/templates/{base → node-vite/examples}/vue/tsconfig.json +2 -2
- package/templates/{vue → node-vite/examples/vue}/vite.config.ts +1 -1
- package/templates/node-vite/package.json +16 -0
- package/templates/node-vite/pnpm-lock.yaml +2293 -0
- package/templates/node-vite/pnpm-workspace.yaml +6 -0
- package/templates/{node → node-vite}/tsconfig.json +1 -1
- package/templates/{node-cli-legacy/tsup.config.ts → node-vite/tsdown.config.ts} +4 -5
- package/templates/vscode-base/.vscode/settings.json +59 -0
- package/templates/{vscode → vscode-base}/.vscode/tasks.json +2 -2
- package/templates/{base/node → vscode-base}/LICENSE +1 -1
- package/templates/{vscode/_gitignore → vscode-base/_.gitignore} +1 -0
- package/templates/vscode-base/locales/zh-CN.json +6 -0
- package/templates/{vscode → vscode-base}/package.json +12 -19
- package/templates/vscode-base/resources/logo.png +0 -0
- package/templates/vscode-base/resources/logo.svg +1 -0
- package/templates/{vscode/tsup.config.ts → vscode-base/tsdown.config.ts} +3 -3
- package/templates/{base/vscode → vscode-react}/.vscode/launch.json +14 -1
- package/templates/vscode-react/.vscode/settings.json +59 -0
- package/templates/{base/vscode → vscode-react}/.vscode/tasks.json +10 -1
- package/templates/{base/vscode → vscode-react}/LICENSE +1 -1
- package/templates/vscode-react/README.md +2 -2
- package/templates/{base/vscode/_gitignore → vscode-react/_.gitignore} +2 -1
- package/templates/{base/vscode → vscode-react}/extension/views/helper.ts +5 -4
- package/templates/{base/vscode → vscode-react}/extension/views/panel.ts +2 -1
- package/templates/vscode-react/package.json +65 -1
- package/templates/vscode-react/pnpm-workspace.yaml +5 -0
- package/templates/vscode-react/src/App.css +1 -1
- package/templates/vscode-react/src/App.tsx +16 -10
- package/templates/vscode-react/src/utils/vscode.ts +2 -81
- package/templates/vscode-react/src/vite-env.d.ts +1 -0
- package/templates/vscode-react/tsconfig.json +5 -0
- package/templates/vscode-react/vite.config.ts +4 -5
- package/templates/vscode-vue/.vscode/extensions.json +5 -0
- package/templates/vscode-vue/.vscode/launch.json +34 -0
- package/templates/vscode-vue/.vscode/settings.json +59 -0
- package/templates/{base/electron → vscode-vue}/.vscode/tasks.json +14 -6
- package/templates/vscode-vue/.vscodeignore +73 -0
- package/templates/vscode-vue/LICENSE +21 -0
- package/templates/vscode-vue/README.md +2 -2
- package/templates/vscode-vue/_.gitignore +65 -0
- package/templates/vscode-vue/extension/env.d.ts +1 -0
- package/templates/vscode-vue/extension/index.ts +21 -0
- package/templates/vscode-vue/extension/views/helper.ts +28 -0
- package/templates/vscode-vue/extension/views/panel.ts +49 -0
- package/templates/vscode-vue/locales/en.json +6 -0
- package/templates/vscode-vue/package.json +56 -2
- package/templates/vscode-vue/pnpm-workspace.yaml +4 -0
- package/templates/vscode-vue/src/App.vue +17 -11
- package/templates/vscode-vue/src/utils/vscode.ts +2 -81
- package/templates/vscode-vue/src/vite-env.d.ts +1 -0
- package/templates/vscode-vue/tsconfig.json +5 -0
- package/templates/vscode-vue/tsconfig.node.json +7 -0
- package/templates/vscode-vue/vite.config.ts +0 -4
- package/templates/web-react/README.md +1 -0
- package/templates/web-react/_eslint.config.mjs +6 -0
- package/templates/web-react/index.html +13 -0
- package/templates/web-react/package.json +27 -0
- package/templates/web-react/public/vite.svg +1 -0
- package/templates/web-react/src/App.css +45 -0
- package/templates/web-react/src/App.tsx +31 -0
- package/templates/web-react/src/assets/react.svg +1 -0
- package/templates/web-react/src/index.css +73 -0
- package/templates/web-react/src/main.tsx +10 -0
- package/templates/web-react/tsconfig.app.json +28 -0
- package/templates/web-react/tsconfig.json +7 -0
- package/templates/web-react/tsconfig.node.json +26 -0
- package/templates/web-react/vite.config.ts +14 -0
- package/templates/web-vue/README.md +1 -0
- package/templates/web-vue/_eslint.config.mjs +6 -0
- package/templates/web-vue/index.html +13 -0
- package/templates/web-vue/package.json +22 -0
- package/templates/web-vue/public/vite.svg +1 -0
- package/templates/web-vue/src/App.vue +32 -0
- package/templates/web-vue/src/assets/vue.svg +1 -0
- package/templates/web-vue/src/components/HelloWorld.vue +19 -0
- package/templates/web-vue/src/main.ts +5 -0
- package/templates/web-vue/src/style.css +84 -0
- package/templates/web-vue/tsconfig.app.json +4 -0
- package/templates/web-vue/tsconfig.json +7 -0
- package/templates/web-vue/tsconfig.node.json +7 -0
- package/templates/web-vue/vite.config.ts +7 -0
- package/templates/base/core/.commitlintrc.cjs +0 -3
- package/templates/base/core/.eslintignore +0 -14
- package/templates/base/core/.husky/commit-msg +0 -1
- package/templates/base/core/.husky/pre-commit +0 -1
- package/templates/base/core/.prettierignore +0 -17
- package/templates/base/core/.prettierrc.cjs +0 -1
- package/templates/base/core/_eslintrc.cjs +0 -7
- package/templates/base/core/_lintstagedrc.cjs +0 -4
- package/templates/base/core/package.json +0 -31
- package/templates/base/electron/electron/main/index.ts +0 -111
- package/templates/base/electron/electron/polyfills.ts +0 -4
- package/templates/base/electron/electron/preload/index.ts +0 -1
- package/templates/base/electron/package.json +0 -25
- package/templates/base/node/README.md +0 -13
- package/templates/base/node/README.zh_CN.md +0 -13
- package/templates/base/node/package.json +0 -47
- package/templates/base/node/test/index.test.ts +0 -7
- package/templates/base/package/package.json +0 -8
- package/templates/base/react/_eslintrc.cjs +0 -7
- package/templates/base/react/_lintstagedrc.cjs +0 -6
- package/templates/base/react/package.json +0 -19
- package/templates/base/react/tsconfig.json +0 -5
- package/templates/base/style/.stylelintignore +0 -16
- package/templates/base/style/.stylelintrc.cjs +0 -3
- package/templates/base/style/_lintstagedrc.cjs +0 -5
- package/templates/base/style/package.json +0 -10
- package/templates/base/vscode/.vscode/settings.json +0 -10
- package/templates/base/vscode/package.json +0 -67
- package/templates/base/vue/_eslintrc.cjs +0 -7
- package/templates/base/vue/_lintstagedrc.cjs +0 -6
- package/templates/base/vue/package.json +0 -17
- package/templates/config.json +0 -108
- package/templates/electron-react/public/img/icon.png +0 -0
- package/templates/electron-vue/public/img/icon.png +0 -0
- package/templates/node/package.json +0 -12
- package/templates/node/src/index.ts +0 -3
- package/templates/node/tsup.config.ts +0 -19
- package/templates/node-cli/index.d.ts +0 -5
- package/templates/node-cli/src/cli.ts +0 -68
- package/templates/node-cli/xxx.config.cjs +0 -0
- package/templates/node-cli-legacy/index.d.ts +0 -5
- package/templates/node-cli-legacy/package.json +0 -31
- package/templates/node-cli-legacy/src/cli.ts +0 -45
- package/templates/node-cli-legacy/src/config.ts +0 -28
- package/templates/node-cli-legacy/src/index.ts +0 -3
- package/templates/node-cli-legacy/src/types.ts +0 -1
- package/templates/node-cli-legacy/src/utils.ts +0 -5
- package/templates/node-vite-plugin/package.json +0 -19
- package/templates/node-vite-plugin/test/index.test.ts +0 -7
- package/templates/node-vite-plugin/tsconfig.json +0 -4
- package/templates/node-vite-plugin/tsup.config.ts +0 -18
- package/templates/node-workspaces/package.json +0 -10
- package/templates/react/package.json +0 -12
- package/templates/react/src/main.tsx +0 -11
- package/templates/react/src/vite-env.d.ts +0 -1
- package/templates/react/vite.config.ts +0 -7
- package/templates/schema.json +0 -110
- package/templates/vscode/.vscode/settings.json +0 -10
- package/templates/vscode/README.md +0 -3
- package/templates/vue/package.json +0 -12
- package/templates/vue/src/components/HelloWorld.vue +0 -37
- package/templates/vue/src/vite-env.d.ts +0 -1
- package/templates/{base/core → config/base}/.gitattributes +0 -0
- package/templates/{node-cli-legacy/xxx.config.cjs → config/base/README.md} +0 -0
- package/templates/{base/electron → electron-react}/electron/env.d.ts +0 -0
- package/templates/{react → node-vite/examples/react}/public/vite.svg +0 -0
- package/templates/{react → node-vite/examples/react}/src/assets/react.svg +0 -0
- package/templates/{base → node-vite/examples}/react/tsconfig.node.json +0 -0
- package/templates/{vue → node-vite/examples/vue}/public/vite.svg +0 -0
- package/templates/{vue → node-vite/examples/vue}/src/assets/vue.svg +0 -0
- package/templates/{base → node-vite/examples}/vue/tsconfig.node.json +0 -0
- package/templates/{node-vite-plugin → node-vite}/src/index.ts +0 -0
- package/templates/{node-vite-plugin → node-vite}/src/types.ts +0 -0
- package/templates/{base/vscode → vscode-base}/.vscode/extensions.json +0 -0
- package/templates/{vscode → vscode-base}/.vscode/launch.json +0 -0
- package/templates/{vscode → vscode-base}/.vscodeignore +0 -0
- package/templates/{base/vscode → vscode-base}/README.md +0 -0
- package/templates/{vscode → vscode-base}/locales/en.json +0 -0
- package/templates/{vscode → vscode-base}/src/index.ts +1 -1
- package/templates/{vscode → vscode-base}/tsconfig.json +0 -0
- package/templates/{vscode → vscode-react}/.vscode/extensions.json +0 -0
- package/templates/{base/vscode → vscode-react}/.vscodeignore +0 -0
- package/templates/{base/vscode → vscode-react}/extension/env.d.ts +0 -0
- package/templates/{base/vscode → vscode-react}/extension/index.ts +1 -1
- /package/templates/{base/vscode → vscode-react}/locales/en.json +0 -0
- /package/templates/{base/vscode → vscode-react}/locales/zh-CN.json +0 -0
- /package/templates/{base/vscode → vscode-react}/resources/logo.png +0 -0
- /package/templates/{base/vscode → vscode-react}/resources/logo.svg +0 -0
- /package/templates/{base/vscode → vscode-react}/tsconfig.node.json +0 -0
- /package/templates/{vscode → vscode-vue}/locales/zh-CN.json +0 -0
- /package/templates/{vscode → vscode-vue}/resources/logo.png +0 -0
- /package/templates/{vscode → vscode-vue}/resources/logo.svg +0 -0
|
@@ -1,14 +1,23 @@
|
|
|
1
|
-
import '../polyfills';
|
|
2
|
-
|
|
3
1
|
import { release } from 'node:os';
|
|
4
2
|
import { join } from 'node:path';
|
|
3
|
+
import { ELECTRON_EXIT } from '@tomjs/vite-plugin-electron/electron';
|
|
5
4
|
import { app, BrowserWindow, ipcMain, shell } from 'electron';
|
|
6
5
|
|
|
6
|
+
console.log('Electron Main Process!');
|
|
7
|
+
|
|
8
|
+
const isDev = process.env.NODE_ENV === 'development';
|
|
9
|
+
process.env.DIST = join(__dirname, '../renderer');
|
|
10
|
+
|
|
11
|
+
console.log('process.env.DIST', process.env.DIST);
|
|
12
|
+
console.log('process.env.VITE_DEV_SERVER_URL', process.env.VITE_DEV_SERVER_URL);
|
|
13
|
+
|
|
7
14
|
// Disable GPU Acceleration for Windows 7
|
|
8
|
-
if (release().startsWith('6.1'))
|
|
15
|
+
if (release().startsWith('6.1'))
|
|
16
|
+
app.disableHardwareAcceleration();
|
|
9
17
|
|
|
10
18
|
// Set application name for Windows 10+ notifications
|
|
11
|
-
if (process.platform === 'win32')
|
|
19
|
+
if (process.platform === 'win32')
|
|
20
|
+
app.setAppUserModelId(app.getName());
|
|
12
21
|
|
|
13
22
|
if (!app.requestSingleInstanceLock()) {
|
|
14
23
|
app.quit();
|
|
@@ -18,24 +27,19 @@ if (!app.requestSingleInstanceLock()) {
|
|
|
18
27
|
// Remove electron security warnings
|
|
19
28
|
// This warning only shows in development mode
|
|
20
29
|
// Read more on https://www.electronjs.org/docs/latest/tutorial/security
|
|
21
|
-
process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true'
|
|
22
|
-
|
|
23
|
-
const isDev = process.env.NODE_ENV === 'development';
|
|
30
|
+
// process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true'
|
|
24
31
|
|
|
25
32
|
let win: BrowserWindow | null = null;
|
|
26
|
-
//
|
|
27
|
-
const preload = join(__dirname, '../preload/index.
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
const indexHtml = join(rendererDist, 'index.html');
|
|
31
|
-
const publicPath = serverUrl ? join(__dirname, '../../public') : rendererDist;
|
|
33
|
+
// Here, you can also use other preload
|
|
34
|
+
const preload = join(__dirname, '../preload/index.js');
|
|
35
|
+
const url = process.env.VITE_DEV_SERVER_URL as string;
|
|
36
|
+
const indexHtml = join(process.env.DIST, 'index.html');
|
|
32
37
|
|
|
33
38
|
function createWindow() {
|
|
34
39
|
win = new BrowserWindow({
|
|
35
40
|
title: 'Main window',
|
|
36
41
|
width: 800,
|
|
37
42
|
height: 700,
|
|
38
|
-
icon: join(publicPath, 'img/icon.png'),
|
|
39
43
|
webPreferences: {
|
|
40
44
|
preload,
|
|
41
45
|
// Warning: Enable nodeIntegration and disable contextIsolation is not secure in production
|
|
@@ -47,12 +51,11 @@ function createWindow() {
|
|
|
47
51
|
});
|
|
48
52
|
|
|
49
53
|
if (isDev) {
|
|
50
|
-
|
|
54
|
+
// electron-vite-vue#298
|
|
55
|
+
win.loadURL(url);
|
|
51
56
|
// Open devTool if the app is not packaged
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}, 500);
|
|
55
|
-
} else {
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
56
59
|
win.loadFile(indexHtml);
|
|
57
60
|
}
|
|
58
61
|
|
|
@@ -63,7 +66,8 @@ function createWindow() {
|
|
|
63
66
|
|
|
64
67
|
// Make all links open with the browser, not with the application
|
|
65
68
|
win.webContents.setWindowOpenHandler(({ url }) => {
|
|
66
|
-
if (url.startsWith('https:'))
|
|
69
|
+
if (url.startsWith('https:'))
|
|
70
|
+
shell.openExternal(url);
|
|
67
71
|
return { action: 'deny' };
|
|
68
72
|
});
|
|
69
73
|
// win.webContents.on('will-navigate', (event, url) => { }) #344
|
|
@@ -73,32 +77,48 @@ app.whenReady().then(async () => {
|
|
|
73
77
|
createWindow();
|
|
74
78
|
|
|
75
79
|
if (isDev) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
'Added Extension: ',
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
80
|
+
try {
|
|
81
|
+
const { installExtension, REACT_DEVELOPER_TOOLS, REDUX_DEVTOOLS } = await import(
|
|
82
|
+
'@tomjs/electron-devtools-installer',
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
installExtension([REACT_DEVELOPER_TOOLS, REDUX_DEVTOOLS])
|
|
86
|
+
.then((exts) => {
|
|
87
|
+
// console.log('Added Extension: ', exts.name);
|
|
88
|
+
// console.log('Added Extension: ', exts.name);
|
|
89
|
+
|
|
90
|
+
// Open devTool if the app is not packaged
|
|
91
|
+
if (win) {
|
|
92
|
+
win.webContents.openDevTools();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
console.log(
|
|
96
|
+
'Added Extension: ',
|
|
97
|
+
exts.map(s => s.name),
|
|
98
|
+
);
|
|
99
|
+
})
|
|
100
|
+
.catch((err) => {
|
|
101
|
+
console.log('Failed to install extensions');
|
|
102
|
+
console.error(err);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
catch (e) {
|
|
106
|
+
console.error(e);
|
|
107
|
+
}
|
|
90
108
|
}
|
|
91
109
|
});
|
|
92
110
|
|
|
93
111
|
app.on('window-all-closed', () => {
|
|
94
112
|
win = null;
|
|
95
|
-
if (process.platform !== 'darwin')
|
|
113
|
+
if (process.platform !== 'darwin')
|
|
114
|
+
app.quit();
|
|
96
115
|
});
|
|
97
116
|
|
|
98
117
|
app.on('second-instance', () => {
|
|
99
118
|
if (win) {
|
|
100
119
|
// Focus on the main window if the user tried to open another
|
|
101
|
-
if (win.isMinimized())
|
|
120
|
+
if (win.isMinimized())
|
|
121
|
+
win.restore();
|
|
102
122
|
win.focus();
|
|
103
123
|
}
|
|
104
124
|
});
|
|
@@ -107,7 +127,8 @@ app.on('activate', () => {
|
|
|
107
127
|
const allWindows = BrowserWindow.getAllWindows();
|
|
108
128
|
if (allWindows.length) {
|
|
109
129
|
allWindows[0].focus();
|
|
110
|
-
}
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
111
132
|
createWindow();
|
|
112
133
|
}
|
|
113
134
|
});
|
|
@@ -122,9 +143,19 @@ ipcMain.handle('open-win', (_, arg) => {
|
|
|
122
143
|
},
|
|
123
144
|
});
|
|
124
145
|
|
|
125
|
-
if (
|
|
126
|
-
childWindow.loadURL(`${
|
|
127
|
-
}
|
|
146
|
+
if (process.env.VITE_DEV_SERVER_URL) {
|
|
147
|
+
childWindow.loadURL(`${url}#${arg}`);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
128
150
|
childWindow.loadFile(indexHtml, { hash: arg });
|
|
129
151
|
}
|
|
130
152
|
});
|
|
153
|
+
|
|
154
|
+
process.on('message', (data) => {
|
|
155
|
+
// electron exit message
|
|
156
|
+
if (data === ELECTRON_EXIT) {
|
|
157
|
+
if (isDev && win) {
|
|
158
|
+
win.webContents.closeDevTools();
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
});
|
|
@@ -4,8 +4,7 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
-
<
|
|
8
|
-
<title>Vite + Electron + React + TS</title>
|
|
7
|
+
<title>Vite + Electron + React</title>
|
|
9
8
|
</head>
|
|
10
9
|
|
|
11
10
|
<body>
|
|
@@ -1,3 +1,37 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
2
|
+
"name": "template-react",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"description": "vite + react",
|
|
6
|
+
"main": "./dist/main/index.js",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=20"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"dev": "vite",
|
|
12
|
+
"debug": "cross-env VITE_ELECTRON_DEBUG=1 vite",
|
|
13
|
+
"build": "vite build",
|
|
14
|
+
"build:pack": "cross-env VITE_ELECTRON_BUILDER=1 vite build",
|
|
15
|
+
"preview": "vite preview"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@tomjs/electron-devtools-installer": "^4.0.1",
|
|
19
|
+
"react": "^19.2.0",
|
|
20
|
+
"react-dom": "^19.2.0"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@eslint-react/eslint-plugin": "^2.3.9",
|
|
24
|
+
"@tomjs/vite-plugin-electron": "^2.0.2",
|
|
25
|
+
"@types/node": "^20.19.25",
|
|
26
|
+
"@types/react": "^19.2.7",
|
|
27
|
+
"@types/react-dom": "^19.2.3",
|
|
28
|
+
"@vitejs/plugin-react-swc": "^4.2.2",
|
|
29
|
+
"cross-env": "^10.1.0",
|
|
30
|
+
"electron": "^39.2.4",
|
|
31
|
+
"eslint-plugin-react-hooks": "^7.0.1",
|
|
32
|
+
"eslint-plugin-react-refresh": "^0.4.24",
|
|
33
|
+
"typescript": "~5.9.3",
|
|
34
|
+
"vite": "^7.2.4",
|
|
35
|
+
"vite-plugin-electron-renderer": "^0.14.6"
|
|
36
|
+
}
|
|
3
37
|
}
|
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
#root {
|
|
2
2
|
max-width: 1280px;
|
|
3
|
-
margin: 0 auto;
|
|
4
3
|
padding: 2rem;
|
|
4
|
+
margin: 0 auto;
|
|
5
5
|
text-align: center;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
.logo {
|
|
9
9
|
height: 6em;
|
|
10
10
|
padding: 1.5em;
|
|
11
|
-
will-change: filter;
|
|
12
11
|
transition: filter 300ms;
|
|
12
|
+
will-change: filter;
|
|
13
13
|
}
|
|
14
|
+
|
|
14
15
|
.logo:hover {
|
|
15
16
|
filter: drop-shadow(0 0 2em #646cffaa);
|
|
16
17
|
}
|
|
18
|
+
|
|
17
19
|
.logo.electron:hover {
|
|
18
20
|
filter: drop-shadow(0 0 2em #1b1c26aa);
|
|
19
21
|
}
|
|
22
|
+
|
|
20
23
|
.logo.react:hover {
|
|
21
24
|
filter: drop-shadow(0 0 2em #61dafbaa);
|
|
22
25
|
}
|
|
@@ -25,6 +28,7 @@
|
|
|
25
28
|
from {
|
|
26
29
|
transform: rotate(0deg);
|
|
27
30
|
}
|
|
31
|
+
|
|
28
32
|
to {
|
|
29
33
|
transform: rotate(360deg);
|
|
30
34
|
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import os from 'node:os';
|
|
2
2
|
import { useState } from 'react';
|
|
3
|
-
import viteLogo from '/vite.svg';
|
|
4
3
|
import electronLogo from './assets/electron.svg';
|
|
5
4
|
import reactLogo from './assets/react.svg';
|
|
6
|
-
|
|
7
5
|
import './App.css';
|
|
8
6
|
|
|
7
|
+
import viteLogo from '/vite.svg';
|
|
8
|
+
|
|
9
9
|
function App() {
|
|
10
10
|
const [count, setCount] = useState(0);
|
|
11
11
|
|
|
12
12
|
const versions = ['chrome', 'node', 'electron']
|
|
13
13
|
.map(s => `${s}: ${process.versions[s]}`)
|
|
14
|
-
.concat([
|
|
14
|
+
.concat([`platform: ${os.platform()} ${os.arch()}`]);
|
|
15
15
|
|
|
16
16
|
return (
|
|
17
17
|
<>
|
|
@@ -29,9 +29,16 @@ function App() {
|
|
|
29
29
|
<h1>Vite + Electron + React</h1>
|
|
30
30
|
<div className="card">
|
|
31
31
|
<div style={{ marginBottom: '1em' }}>{versions.join(', ')}</div>
|
|
32
|
-
<button onClick={() => setCount(count => count + 1)}>
|
|
32
|
+
<button onClick={() => setCount(count => count + 1)}>
|
|
33
|
+
count is
|
|
34
|
+
{count}
|
|
35
|
+
</button>
|
|
33
36
|
<p>
|
|
34
|
-
Edit
|
|
37
|
+
Edit
|
|
38
|
+
{' '}
|
|
39
|
+
<code>src/App.tsx</code>
|
|
40
|
+
{' '}
|
|
41
|
+
and save to test HMR
|
|
35
42
|
</p>
|
|
36
43
|
</div>
|
|
37
44
|
<p className="read-the-docs">Click on the Vite and React logos to learn more</p>
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
:root {
|
|
2
2
|
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
|
|
3
|
-
line-height: 1.5;
|
|
4
3
|
font-weight: 400;
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
font-synthesis: none;
|
|
6
|
+
line-height: 1.5;
|
|
7
7
|
color: rgba(255, 255, 255, 0.87);
|
|
8
|
-
background-color: #242424;
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
color-scheme: light dark;
|
|
10
|
+
background-color: #242424;
|
|
11
11
|
text-rendering: optimizeLegibility;
|
|
12
12
|
-webkit-font-smoothing: antialiased;
|
|
13
13
|
-moz-osx-font-smoothing: grayscale;
|
|
@@ -19,16 +19,17 @@ a {
|
|
|
19
19
|
color: #646cff;
|
|
20
20
|
text-decoration: inherit;
|
|
21
21
|
}
|
|
22
|
+
|
|
22
23
|
a:hover {
|
|
23
24
|
color: #535bf2;
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
body {
|
|
27
|
-
margin: 0;
|
|
28
28
|
display: flex;
|
|
29
29
|
place-items: center;
|
|
30
30
|
min-width: 320px;
|
|
31
31
|
min-height: 100vh;
|
|
32
|
+
margin: 0;
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
h1 {
|
|
@@ -37,19 +38,21 @@ h1 {
|
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
button {
|
|
40
|
-
border-radius: 8px;
|
|
41
|
-
border: 1px solid transparent;
|
|
42
41
|
padding: 0.6em 1.2em;
|
|
42
|
+
font-family: inherit;
|
|
43
43
|
font-size: 1em;
|
|
44
44
|
font-weight: 500;
|
|
45
|
-
font-family: inherit;
|
|
46
|
-
background-color: #1a1a1a;
|
|
47
45
|
cursor: pointer;
|
|
46
|
+
background-color: #1a1a1a;
|
|
47
|
+
border: 1px solid transparent;
|
|
48
|
+
border-radius: 8px;
|
|
48
49
|
transition: border-color 0.25s;
|
|
49
50
|
}
|
|
51
|
+
|
|
50
52
|
button:hover {
|
|
51
53
|
border-color: #646cff;
|
|
52
54
|
}
|
|
55
|
+
|
|
53
56
|
button:focus,
|
|
54
57
|
button:focus-visible {
|
|
55
58
|
outline: 4px auto -webkit-focus-ring-color;
|
|
@@ -60,9 +63,11 @@ button:focus-visible {
|
|
|
60
63
|
color: #213547;
|
|
61
64
|
background-color: #ffffff;
|
|
62
65
|
}
|
|
66
|
+
|
|
63
67
|
a:hover {
|
|
64
68
|
color: #747bff;
|
|
65
69
|
}
|
|
70
|
+
|
|
66
71
|
button {
|
|
67
72
|
background-color: #f9f9f9;
|
|
68
73
|
}
|
|
@@ -1,27 +1,14 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
1
|
import electron from '@tomjs/vite-plugin-electron';
|
|
3
2
|
import react from '@vitejs/plugin-react-swc';
|
|
4
3
|
import { defineConfig } from 'vite';
|
|
5
4
|
import renderer from 'vite-plugin-electron-renderer';
|
|
6
|
-
import pkg from './package.json';
|
|
7
5
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
alias: {
|
|
17
|
-
'@': path.join(__dirname, 'src'),
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
plugins: [
|
|
21
|
-
react(),
|
|
22
|
-
electron(),
|
|
23
|
-
// Use Node.js API in the Renderer process
|
|
24
|
-
renderer(),
|
|
25
|
-
],
|
|
26
|
-
};
|
|
6
|
+
export default defineConfig({
|
|
7
|
+
plugins: [
|
|
8
|
+
react(),
|
|
9
|
+
electron({
|
|
10
|
+
external: ['fs-extra'],
|
|
11
|
+
}),
|
|
12
|
+
renderer(),
|
|
13
|
+
],
|
|
27
14
|
});
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
"configurations": [
|
|
7
|
+
{
|
|
8
|
+
"name": "Debug Electron",
|
|
9
|
+
"type": "node",
|
|
10
|
+
"request": "launch",
|
|
11
|
+
"cwd": "${workspaceFolder}",
|
|
12
|
+
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
|
|
13
|
+
"windows": {
|
|
14
|
+
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron.cmd"
|
|
15
|
+
},
|
|
16
|
+
"args": [
|
|
17
|
+
"."
|
|
18
|
+
],
|
|
19
|
+
"outFiles": [
|
|
20
|
+
"${workspaceFolder}/**/*.js",
|
|
21
|
+
"${workspaceFolder}/**/*.cjs",
|
|
22
|
+
"${workspaceFolder}/**/*.mjs",
|
|
23
|
+
"!**/node_modules/**"
|
|
24
|
+
],
|
|
25
|
+
"preLaunchTask": "npm:dev"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"name": "Debug Web",
|
|
29
|
+
"type": "node",
|
|
30
|
+
"request": "launch",
|
|
31
|
+
"cwd": "${workspaceFolder}",
|
|
32
|
+
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
|
|
33
|
+
"windows": {
|
|
34
|
+
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron.cmd"
|
|
35
|
+
},
|
|
36
|
+
"args": [
|
|
37
|
+
"."
|
|
38
|
+
],
|
|
39
|
+
"outFiles": [
|
|
40
|
+
"${workspaceFolder}/**/*.js",
|
|
41
|
+
"${workspaceFolder}/**/*.cjs",
|
|
42
|
+
"${workspaceFolder}/**/*.mjs",
|
|
43
|
+
"!**/node_modules/**"
|
|
44
|
+
],
|
|
45
|
+
"preLaunchTask": "npm:debug"
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
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
|
+
"type": "npm",
|
|
8
|
+
"script": "dev",
|
|
9
|
+
"label": "npm:dev",
|
|
10
|
+
"problemMatcher": {
|
|
11
|
+
"owner": "typescript",
|
|
12
|
+
"fileLocation": "relative",
|
|
13
|
+
"pattern": {
|
|
14
|
+
"regexp": "^([a-zA-Z]\\:\\/?([\\w\\-]\\/?)+\\.\\w+):(\\d+):(\\d+): (ERROR|WARNING)\\: (.*)$",
|
|
15
|
+
"file": 1,
|
|
16
|
+
"line": 3,
|
|
17
|
+
"column": 4,
|
|
18
|
+
"code": 5,
|
|
19
|
+
"message": 6
|
|
20
|
+
},
|
|
21
|
+
"background": {
|
|
22
|
+
"activeOnStart": true,
|
|
23
|
+
"beginsPattern": "^.*VITE v.* ready in \\d* ms.*$",
|
|
24
|
+
"endsPattern": "^.*\\[tomjs:electron\\] startup electron*$"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"isBackground": true,
|
|
28
|
+
"presentation": {
|
|
29
|
+
"reveal": "never"
|
|
30
|
+
},
|
|
31
|
+
"group": {
|
|
32
|
+
"kind": "build",
|
|
33
|
+
"isDefault": true
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"type": "npm",
|
|
38
|
+
"script": "debug",
|
|
39
|
+
"label": "npm:debug",
|
|
40
|
+
"problemMatcher": {
|
|
41
|
+
"owner": "typescript",
|
|
42
|
+
"fileLocation": "relative",
|
|
43
|
+
"pattern": {
|
|
44
|
+
"regexp": "^([a-zA-Z]\\:\\/?([\\w\\-]\\/?)+\\.\\w+):(\\d+):(\\d+): (ERROR|WARNING)\\: (.*)$",
|
|
45
|
+
"file": 1,
|
|
46
|
+
"line": 3,
|
|
47
|
+
"column": 4,
|
|
48
|
+
"code": 5,
|
|
49
|
+
"message": 6
|
|
50
|
+
},
|
|
51
|
+
"background": {
|
|
52
|
+
"activeOnStart": true,
|
|
53
|
+
"beginsPattern": "^.*VITE v.* ready in \\d* ms.*$",
|
|
54
|
+
"endsPattern": "^.*\\[tomjs:electron\\] startup electron*$"
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"isBackground": true,
|
|
58
|
+
"presentation": {
|
|
59
|
+
"reveal": "never"
|
|
60
|
+
},
|
|
61
|
+
"group": {
|
|
62
|
+
"kind": "build",
|
|
63
|
+
"isDefault": true
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
]
|
|
67
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="@tomjs/vite-plugin-electron/env" />
|