diff --git a/script/rollup.config.ts b/script/rollup.config.ts index 98e5f14..4b47dbf 100644 --- a/script/rollup.config.ts +++ b/script/rollup.config.ts @@ -25,8 +25,10 @@ export default (env = 'production') => { }), alias({ entries: [ - { find: '@main', replacement: join(__dirname, '../src/main'), }, - { find: '@root', replacement: join(__dirname, '..'), }, + { find: '@render', replacement: join(__dirname, '../src/render') }, + { find: '@main', replacement: join(__dirname, '../src/main') }, + { find: '@src', replacement: join(__dirname, '../src') }, + { find: '@root', replacement: join(__dirname, '..') }, ] }), ], diff --git a/src/common/patch.ts b/src/common/patch.ts new file mode 100644 index 0000000..4ebac47 --- /dev/null +++ b/src/common/patch.ts @@ -0,0 +1,4 @@ +/** + * !!! ensure process.cwd() correct + */ +process.chdir(__dirname.slice(0, __dirname.lastIndexOf('dist'))) diff --git a/src/main/index.ts b/src/main/index.ts index a8b58b3..40a1a51 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -1,6 +1,7 @@ /** * electron 主文件 */ +import '@src/common/patch' import { join } from 'path' import { app, BrowserWindow } from 'electron' import dotenv from 'dotenv' diff --git a/src/render/main.ts b/src/render/main.ts index 5d4e47b..1051be6 100644 --- a/src/render/main.ts +++ b/src/render/main.ts @@ -1,8 +1,4 @@ -/** - * !!! ensure cwd crrect - */ -process.chdir(__dirname) - +import '@src/common/patch' import { createApp } from 'vue' import App from './App.vue' import fs = require('fs') diff --git a/tsconfig.json b/tsconfig.json index 6bc2b14..a42f71f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,8 +11,9 @@ "baseUrl": "./", "strict": true, "paths": { - "@/*": ["src/render/*"], + "@render/*": ["src/render/*"], "@main/*": ["src/main/*"], + "@src/*": ["src/*"], "@root/*": ["./*"] }, "allowSyntheticDefaultImports": true diff --git a/vite.config.ts b/vite.config.ts index 86081b9..1a2e18d 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -18,7 +18,9 @@ export default defineConfig({ }, resolve: { alias: { - '@': join(__dirname, 'src/render'), + '@render': join(__dirname, 'src/render'), + '@main': join(__dirname, 'src/main'), + '@src': join(__dirname, 'src'), '@root': __dirname, }, },