electron-vite-vue/vite.config.ts

74 lines
1.7 KiB
TypeScript
Raw Normal View History

2021-02-18 16:11:08 +08:00
require('dotenv').config({ path: join(__dirname, '.env') })
2021-02-17 22:27:40 +08:00
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
2021-02-18 16:11:08 +08:00
import { join } from 'path'
2021-05-15 16:30:59 +08:00
// import typescript from '@rollup/plugin-typescript'
2021-05-16 19:53:54 +08:00
import { builtins } from './script/utils'
import {
// ensureCwdCrrect,
esm2cjs,
} from './script/plugins'
2021-05-15 16:30:59 +08:00
const root = join(__dirname, 'src/render')
2020-08-16 20:42:52 +08:00
2021-02-17 22:27:40 +08:00
// https://vitejs.dev/config/
2021-05-16 20:14:05 +08:00
export default defineConfig(env => {
const isserve = env.command === 'serve'
return {
plugins: [
vue(),
...(isserve ? [
/**
* !!! electron commonjs vite
*/
esm2cjs([
'electron',
'electron-store',
]),
] : []),
],
root,
base: './', // index.html 中静态资源加载位置
server: {
port: +process.env.PORT,
2021-02-17 22:27:40 +08:00
},
2021-05-16 20:14:05 +08:00
resolve: {
alias: {
'@render': join(__dirname, 'src/render'),
'@main': join(__dirname, 'src/main'),
'@src': join(__dirname, 'src'),
'@root': __dirname,
},
},
optimizeDeps: {
exclude: [
2021-04-01 10:30:24 +08:00
'electron',
2021-05-16 20:14:05 +08:00
'electron-store', // optional
2021-02-17 22:27:40 +08:00
],
2021-05-16 20:14:05 +08:00
},
build: {
outDir: join(__dirname, 'dist/render'),
emptyOutDir: true,
minify: false,
commonjsOptions: {},
assetsDir: '', // 相对路径 加载问题
sourcemap: true,
rollupOptions: {
plugins: [
// typescript({ module: 'ESNext' }),
// ensureCwdCrrect(join(root, 'main.ts')),
],
external: [
...builtins(),
'electron',
],
output: {
format: 'cjs',
},
2021-04-01 10:30:24 +08:00
},
2021-02-17 22:27:40 +08:00
},
2021-05-16 20:14:05 +08:00
}
2021-02-17 22:27:40 +08:00
})