feat: use vitejs-plugin-electron

This commit is contained in:
草鞋没号 2021-05-23 10:35:34 +08:00
parent 8bbc770d69
commit e7406e9c13
3 changed files with 12 additions and 22 deletions

View File

@ -75,7 +75,8 @@
"rollup-plugin-esbuild": "^4.2.3", "rollup-plugin-esbuild": "^4.2.3",
"ts-node": "^9.1.1", "ts-node": "^9.1.1",
"typescript": "^4.2.4", "typescript": "^4.2.4",
"vite": "^2.2.4" "vite": "^2.2.4",
"vitejs-plugin-electron": "^0.0.4"
}, },
"keywords": [ "keywords": [
"vite", "vite",

View File

@ -3,32 +3,19 @@ require('dotenv').config({ path: join(__dirname, '.env') })
import { defineConfig } from 'vite' import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue' import vue from '@vitejs/plugin-vue'
import { join } from 'path' import { join } from 'path'
// import typescript from '@rollup/plugin-typescript'
import { builtins } from './script/utils' import { builtins } from './script/utils'
import { import electron from 'vitejs-plugin-electron'
// ensureCwdCrrect,
esm2cjs,
} from './script/plugins'
const root = join(__dirname, 'src/render') const root = join(__dirname, 'src/render')
// https://vitejs.dev/config/
export default defineConfig(env => { export default defineConfig(env => {
const isserve = env.command === 'serve' const isserve = env.command === 'serve'
return { return {
plugins: [ plugins: [
vue(), vue(),
...(isserve ? [ isserve && electron({}),
/** ].filter(Boolean),
* !!! electron commonjs vite
*/
esm2cjs([
'electron',
'electron-store',
]),
] : []),
],
root, root,
base: './', // index.html 中静态资源加载位置 base: './', // index.html 中静态资源加载位置
server: { server: {
@ -45,7 +32,6 @@ export default defineConfig(env => {
optimizeDeps: { optimizeDeps: {
exclude: [ exclude: [
'electron', 'electron',
// 'electron-store', // optional
], ],
}, },
build: { build: {
@ -56,10 +42,6 @@ export default defineConfig(env => {
assetsDir: '', // 相对路径 加载问题 assetsDir: '', // 相对路径 加载问题
sourcemap: true, sourcemap: true,
rollupOptions: { rollupOptions: {
plugins: [
// typescript({ module: 'ESNext' }),
// ensureCwdCrrect(join(root, 'main.ts')),
],
external: [ external: [
...builtins(), ...builtins(),
'electron', 'electron',

View File

@ -2816,6 +2816,13 @@ vite@^2.2.4:
optionalDependencies: optionalDependencies:
fsevents "~2.3.1" 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: vue@^3.0.11:
version "3.0.11" version "3.0.11"
resolved "https://registry.yarnpkg.com/vue/-/vue-3.0.11.tgz#c82f9594cbf4dcc869241d4c8dd3e08d9a8f4b5f" resolved "https://registry.yarnpkg.com/vue/-/vue-3.0.11.tgz#c82f9594cbf4dcc869241d4c8dd3e08d9a8f4b5f"