diff --git a/package.json b/package.json index fb07c45..c6d45ee 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,8 @@ "rollup-plugin-esbuild": "^4.2.3", "ts-node": "^9.1.1", "typescript": "^4.2.4", - "vite": "^2.2.4" + "vite": "^2.2.4", + "vitejs-plugin-electron": "^0.0.4" }, "keywords": [ "vite", diff --git a/vite.config.ts b/vite.config.ts index c5e653c..323f665 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -3,32 +3,19 @@ require('dotenv').config({ path: join(__dirname, '.env') }) import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' import { join } from 'path' -// import typescript from '@rollup/plugin-typescript' import { builtins } from './script/utils' -import { - // ensureCwdCrrect, - esm2cjs, -} from './script/plugins' +import electron from 'vitejs-plugin-electron' const root = join(__dirname, 'src/render') -// https://vitejs.dev/config/ export default defineConfig(env => { const isserve = env.command === 'serve' return { plugins: [ vue(), - ...(isserve ? [ - /** - * !!! 开发期将 electron 及相关模块转换成 commonjs 避开 vite 处理 - */ - esm2cjs([ - 'electron', - 'electron-store', - ]), - ] : []), - ], + isserve && electron({}), + ].filter(Boolean), root, base: './', // index.html 中静态资源加载位置 server: { @@ -45,7 +32,6 @@ export default defineConfig(env => { optimizeDeps: { exclude: [ 'electron', - // 'electron-store', // optional ], }, build: { @@ -56,10 +42,6 @@ export default defineConfig(env => { assetsDir: '', // 相对路径 加载问题 sourcemap: true, rollupOptions: { - plugins: [ - // typescript({ module: 'ESNext' }), - // ensureCwdCrrect(join(root, 'main.ts')), - ], external: [ ...builtins(), 'electron', diff --git a/yarn.lock b/yarn.lock index 05331cd..6071125 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2816,6 +2816,13 @@ vite@^2.2.4: optionalDependencies: fsevents "~2.3.1" +vitejs-plugin-electron@^0.0.4: + version "0.0.4" + resolved "https://registry.yarnpkg.com/vitejs-plugin-electron/-/vitejs-plugin-electron-0.0.4.tgz#b6ce83510572cf50c55cc9f35d6a847d7fcd67b4" + integrity sha512-mD4weY2OJaDY48i5P4LNYV10wS490MvZG4y9egfve75Qs89nZ6G8mfdRId+3bL36AKGJuvEWLiuzpV0dHSAqwA== + dependencies: + acorn "^8.2.4" + vue@^3.0.11: version "3.0.11" resolved "https://registry.yarnpkg.com/vue/-/vue-3.0.11.tgz#c82f9594cbf4dcc869241d4c8dd3e08d9a8f4b5f"