From 9d702430f0aff40730dcc9fc30b34100ca0da89e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8D=89=E9=9E=8B=E6=B2=A1=E5=8F=B7?= <308487730@qq.com> Date: Tue, 8 Feb 2022 10:34:14 +0800 Subject: [PATCH] src -> packages --- README.md | 12 ++++++------ README.zh-CN.md | 18 ++++++++++++------ package.json | 2 +- {src => packages}/main/index.ts | 0 {src => packages}/preload/index.ts | 0 {src => packages}/preload/loading.ts | 0 {src => packages}/preload/utils.ts | 0 {src => packages}/renderer/index.html | 0 {src => packages}/renderer/public/favicon.ico | Bin .../renderer/public/images/node.png | Bin {src => packages}/renderer/src/App.vue | 0 .../renderer/src/assets/electron.png | Bin .../renderer/src/assets/vite.svg | 0 {src => packages}/renderer/src/assets/vue.png | Bin .../renderer/src/components/HelloWorld.vue | 0 {src => packages}/renderer/src/env.d.ts | 0 {src => packages}/renderer/src/global.d.ts | 0 {src => packages}/renderer/src/main.ts | 0 {src => packages}/renderer/tsconfig.json | 0 {src => packages}/renderer/vite.config.ts | 0 scripts/build.mjs | 6 +++--- scripts/watch.mjs | 6 +++--- 22 files changed, 25 insertions(+), 19 deletions(-) rename {src => packages}/main/index.ts (100%) rename {src => packages}/preload/index.ts (100%) rename {src => packages}/preload/loading.ts (100%) rename {src => packages}/preload/utils.ts (100%) rename {src => packages}/renderer/index.html (100%) rename {src => packages}/renderer/public/favicon.ico (100%) rename {src => packages}/renderer/public/images/node.png (100%) rename {src => packages}/renderer/src/App.vue (100%) rename {src => packages}/renderer/src/assets/electron.png (100%) rename {src => packages}/renderer/src/assets/vite.svg (100%) rename {src => packages}/renderer/src/assets/vue.png (100%) rename {src => packages}/renderer/src/components/HelloWorld.vue (100%) rename {src => packages}/renderer/src/env.d.ts (100%) rename {src => packages}/renderer/src/global.d.ts (100%) rename {src => packages}/renderer/src/main.ts (100%) rename {src => packages}/renderer/tsconfig.json (100%) rename {src => packages}/renderer/vite.config.ts (100%) diff --git a/README.md b/README.md index e9fa40c..52c770f 100644 --- a/README.md +++ b/README.md @@ -38,11 +38,11 @@ You can learn more details by looking at the source code. Trust me, this templat ## Directory -Once `dev` or `build` npm-script executed will be generate named `dist` folder. It has children dir of same as `src` folder, the purpose of this design can ensure the correct path calculation. +Once `dev` or `build` npm-script executed will be generate named `dist` folder. It has children dir of same as `packages` folder, the purpose of this design can ensure the correct path calculation. ```tree ├ -├── dist After build, it's generated according to the "src" directory +├── dist After build, it's generated according to the "packages" directory ├ ├── main ├ ├── preload ├ ├── renderer @@ -52,7 +52,7 @@ Once `dev` or `build` npm-script executed will be generate named `dist` folder. ├ ├── vite.config.mjs Marin-process, Preload-script vite-config ├ ├── watch.mjs Develop script, for -> npm run dev ├ -├── src +├── packages ├ ├── main Main-process source code ├ ├── preload Preload-script source code ├ ├── renderer Renderer-process source code @@ -66,7 +66,7 @@ Once `dev` or `build` npm-script executed will be generate named `dist` folder. #### All Electron, NodeJs API invoke passed `Preload-script` -* **src/preload/index.ts** +* **packages/preload/index.ts** ```typescript import fs from 'fs' @@ -77,7 +77,7 @@ Once `dev` or `build` npm-script executed will be generate named `dist` folder. contextBridge.exposeInMainWorld('ipcRenderer', ipcRenderer) ``` -* **src/renderer/src/global.d.ts** +* **packages/renderer/src/global.d.ts** ```typescript // Defined on the window @@ -87,7 +87,7 @@ Once `dev` or `build` npm-script executed will be generate named `dist` folder. } ``` -* **src/renderer/src/main.ts** +* **packages/renderer/src/main.ts** ```typescript // Use Electron, NodeJs API in Renderer-process diff --git a/README.zh-CN.md b/README.zh-CN.md index 60268d3..3ab6e0a 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -38,11 +38,11 @@ ## 目录结构 -  一旦启动或打包脚本执行过,会在根目录产生 **`dist` 文件夹,里面的文件夹同 `src` 一模一样**;在使用一些路径计算时,尤其是相对路径计算;`dist` 与 `src` 里面保持相同的目录结构能避开好多问题 +  一旦启动或打包脚本执行过,会在根目录产生 **`dist` 文件夹,里面的文件夹同 `packages` 一模一样**;在使用一些路径计算时,尤其是相对路径计算;`dist` 与 `packages` 里面保持相同的目录结构能避开好多问题 ```tree ├ -├── dist 构建后,根据 src 目录生成 +├── dist 构建后,根据 packages 目录生成 ├ ├── main ├ ├── preload ├ ├── renderer @@ -52,7 +52,7 @@ ├ ├── vite.config.mjs 主进程, 预加载脚本源码 vite 配置 ├ ├── watch.mjs 项目开发脚本,对应 npm run dev ├ -├── src +├── packages ├ ├── main 主进程源码 ├ ├── preload 预加载脚本源码 ├ ├── renderer 渲染进程源码 @@ -78,7 +78,7 @@ electron-builder 打包时候会将 dependencies 中的包打包到 app.asar 里 **推荐所有的 NodeJs、Electron API 通过 `Preload-script` 注入到 渲染进程中,例如:** -* **src/preload/index.ts** +* **packages/preload/index.ts** ```typescript import fs from 'fs' @@ -89,7 +89,7 @@ electron-builder 打包时候会将 dependencies 中的包打包到 app.asar 里 contextBridge.exposeInMainWorld('ipcRenderer', ipcRenderer) ``` -* **src/renderer/src/global.d.ts** +* **packages/renderer/src/global.d.ts** ```typescript // Defined on the window @@ -99,7 +99,13 @@ electron-builder 打包时候会将 dependencies 中的包打包到 app.asar 里 } ``` -* **src/renderer/main.ts** +* **packages/renderer/src/main.ts** + + ```typescript + // Use Electron, NodeJs API in Renderer-process + console.log('fs', window.fs) + console.log('ipcRenderer', window.ipcRenderer) + ``` ```typescript // Use Electron, NodeJs API in Renderer-process diff --git a/package.json b/package.json index 9c90dcc..debc0cd 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "license": "MIT", "scripts": { "dev": "node scripts/watch.mjs", - "build": "vue-tsc --project src/renderer/tsconfig.json --noEmit && node scripts/build.mjs && electron-builder" + "build": "vue-tsc --project packages/renderer/tsconfig.json --noEmit && node scripts/build.mjs && electron-builder" }, "engines": { "node": ">=14.17.0" diff --git a/src/main/index.ts b/packages/main/index.ts similarity index 100% rename from src/main/index.ts rename to packages/main/index.ts diff --git a/src/preload/index.ts b/packages/preload/index.ts similarity index 100% rename from src/preload/index.ts rename to packages/preload/index.ts diff --git a/src/preload/loading.ts b/packages/preload/loading.ts similarity index 100% rename from src/preload/loading.ts rename to packages/preload/loading.ts diff --git a/src/preload/utils.ts b/packages/preload/utils.ts similarity index 100% rename from src/preload/utils.ts rename to packages/preload/utils.ts diff --git a/src/renderer/index.html b/packages/renderer/index.html similarity index 100% rename from src/renderer/index.html rename to packages/renderer/index.html diff --git a/src/renderer/public/favicon.ico b/packages/renderer/public/favicon.ico similarity index 100% rename from src/renderer/public/favicon.ico rename to packages/renderer/public/favicon.ico diff --git a/src/renderer/public/images/node.png b/packages/renderer/public/images/node.png similarity index 100% rename from src/renderer/public/images/node.png rename to packages/renderer/public/images/node.png diff --git a/src/renderer/src/App.vue b/packages/renderer/src/App.vue similarity index 100% rename from src/renderer/src/App.vue rename to packages/renderer/src/App.vue diff --git a/src/renderer/src/assets/electron.png b/packages/renderer/src/assets/electron.png similarity index 100% rename from src/renderer/src/assets/electron.png rename to packages/renderer/src/assets/electron.png diff --git a/src/renderer/src/assets/vite.svg b/packages/renderer/src/assets/vite.svg similarity index 100% rename from src/renderer/src/assets/vite.svg rename to packages/renderer/src/assets/vite.svg diff --git a/src/renderer/src/assets/vue.png b/packages/renderer/src/assets/vue.png similarity index 100% rename from src/renderer/src/assets/vue.png rename to packages/renderer/src/assets/vue.png diff --git a/src/renderer/src/components/HelloWorld.vue b/packages/renderer/src/components/HelloWorld.vue similarity index 100% rename from src/renderer/src/components/HelloWorld.vue rename to packages/renderer/src/components/HelloWorld.vue diff --git a/src/renderer/src/env.d.ts b/packages/renderer/src/env.d.ts similarity index 100% rename from src/renderer/src/env.d.ts rename to packages/renderer/src/env.d.ts diff --git a/src/renderer/src/global.d.ts b/packages/renderer/src/global.d.ts similarity index 100% rename from src/renderer/src/global.d.ts rename to packages/renderer/src/global.d.ts diff --git a/src/renderer/src/main.ts b/packages/renderer/src/main.ts similarity index 100% rename from src/renderer/src/main.ts rename to packages/renderer/src/main.ts diff --git a/src/renderer/tsconfig.json b/packages/renderer/tsconfig.json similarity index 100% rename from src/renderer/tsconfig.json rename to packages/renderer/tsconfig.json diff --git a/src/renderer/vite.config.ts b/packages/renderer/vite.config.ts similarity index 100% rename from src/renderer/vite.config.ts rename to packages/renderer/vite.config.ts diff --git a/scripts/build.mjs b/scripts/build.mjs index f894437..2e538fb 100644 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -8,7 +8,7 @@ const __dirname = dirname(fileURLToPath(import.meta.url)) await build({ configFile: 'scripts/vite.config.mjs', - root: join(__dirname, '../src/main'), + root: join(__dirname, '../packages/main'), build: { outDir: '../../dist/main', }, @@ -16,10 +16,10 @@ await build({ await build({ configFile: 'scripts/vite.config.mjs', - root: join(__dirname, '../src/preload'), + root: join(__dirname, '../packages/preload'), build: { outDir: '../../dist/preload', }, }) -await build({ configFile: 'src/renderer/vite.config.ts' }) +await build({ configFile: 'packages/renderer/vite.config.ts' }) diff --git a/scripts/watch.mjs b/scripts/watch.mjs index 7b4e68d..fd7f1cc 100644 --- a/scripts/watch.mjs +++ b/scripts/watch.mjs @@ -22,7 +22,7 @@ function watchMain() { return build({ configFile: 'scripts/vite.config.mjs', - root: join(__dirname, '../src/main'), + root: join(__dirname, '../packages/main'), build: { outDir: '../../dist/main', watch: true, @@ -46,7 +46,7 @@ function watchMain() { function watchPreload(server) { return build({ configFile: 'scripts/vite.config.mjs', - root: join(__dirname, '../src/preload'), + root: join(__dirname, '../packages/preload'), build: { outDir: '../../dist/preload', watch: true, @@ -61,7 +61,7 @@ function watchPreload(server) { } // bootstrap -const server = await createServer({ configFile: 'src/renderer/vite.config.ts' }) +const server = await createServer({ configFile: 'packages/renderer/vite.config.ts' }) await server.listen() await watchPreload(server)