forked from Language-Research-Technology/crate-o
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.js
104 lines (100 loc) · 2.73 KB
/
vite.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { fileURLToPath, URL } from 'node:url'
import { readFile } from "node:fs/promises";
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
//import { createHtmlPlugin } from 'vite-plugin-html'
// import AutoImport from 'unplugin-auto-import/vite'
// import Components from 'unplugin-vue-components/vite'
// import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import ElementPlus from 'unplugin-element-plus/vite'
import tailwindcss from 'tailwindcss';
import autoprefixer from 'autoprefixer';
import { visualizer } from "rollup-plugin-visualizer";
import { compile } from "ejs";
/// <reference types="vitest" />
const build = {
_all: {
rollupOptions: {},
commonjsOptions: {
include: [/ro-crate-excel/, /node_modules/],
transformMixedEsModules: true
},
},
production: {},
library: {
lib: {
entry: fileURLToPath(new URL('./src/lib/index.js', import.meta.url)),
formats: ['es']
},
minify: false,
rollupOptions: {
external: ['vue', 'element-plus'],
output: {
globals: {
vue: 'Vue',
"element-plus": "ElementPlus"
},
},
},
}
}
const ejsRenderer = await createRenderer();
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => ({
plugins: [
ejsRenderer,
visualizer(),
vue(),
//createHtmlPlugin({minify: true, entry: 'src/app/main.js'}),
ElementPlus()
// AutoImport({resolvers: [ElementPlusResolver()]}),
// Components({resolvers: [ElementPlusResolver()]})
],
css: {
postcss: {
plugins: [tailwindcss, autoprefixer],
},
},
optimizeDeps: {
include: ['ro-crate-excel', 'leaflet', 'ro-crate-html']
},
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
esbuild: {
drop: mode !== 'development' ? ['console', 'debugger'] : [],
},
base: './',
build: build[mode],
define: {
__APP_VERSION__: JSON.stringify(process.env.npm_package_version)
},
test: {
globals: true,
environment: 'jsdom',
deps: {
inline: ['element-plus']
}
}
}));
async function createRenderer() {
const virtualModuleId = 'virtual:ejs';
const resolvedVirtualModuleId = '\0' + virtualModuleId;
const tp = fileURLToPath(import.meta.resolve('ro-crate-html/defaults/metadata_template.html'));
const src = await readFile(tp, "utf-8");
const code = compile(src, { client: true, strict: true });
//const template = await buildPreviewTemplate();
return {
name: 'ejsRenderer',
resolveId(id) {
if (id === virtualModuleId) return resolvedVirtualModuleId;
},
load(id) {
if (id === resolvedVirtualModuleId) {
return `export default ${code.toString()}`;
}
}
};
}