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",
"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",

View File

@ -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',

View File

@ -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"