electron-vite-vue/vite.config.ts

62 lines
1.3 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/
export default defineConfig({
2021-05-16 19:53:54 +08:00
plugins: [
vue(),
esm2cjs([
'electron',
'electron-store',
]),
],
2021-05-15 16:30:59 +08:00
root,
2021-02-18 17:29:45 +08:00
base: './', // index.html 中静态资源加载位置
2021-02-17 22:27:40 +08:00
server: {
port: +process.env.PORT,
},
resolve: {
alias: {
2021-05-15 20:57:32 +08:00
'@render': join(__dirname, 'src/render'),
'@main': join(__dirname, 'src/main'),
'@src': join(__dirname, 'src'),
2021-02-17 22:27:40 +08:00
'@root': __dirname,
},
2020-08-31 09:50:57 +08:00
},
2021-05-16 19:53:54 +08:00
optimizeDeps: {
exclude: ['electron'],
},
2021-02-17 22:27:40 +08:00
build: {
outDir: join(__dirname, 'dist/render'),
2021-04-01 10:30:24 +08:00
emptyOutDir: true,
minify: false,
2021-05-15 16:30:59 +08:00
commonjsOptions: {},
assetsDir: '', // 相对路径 加载问题
sourcemap: true,
2021-02-17 22:27:40 +08:00
rollupOptions: {
plugins: [
2021-05-15 16:30:59 +08:00
// typescript({ module: 'ESNext' }),
// ensureCwdCrrect(join(root, 'main.ts')),
],
2021-04-01 10:30:24 +08:00
external: [
...builtins(),
'electron',
2021-02-17 22:27:40 +08:00
],
2021-04-01 10:30:24 +08:00
output: {
format: 'cjs',
},
2021-02-17 22:27:40 +08:00
},
2020-09-25 11:39:39 +08:00
},
2021-02-17 22:27:40 +08:00
})