-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathvite.config.ts
99 lines (91 loc) · 2.14 KB
/
vite.config.ts
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
import path from 'node:path'
import commonjs from '@rollup/plugin-commonjs'
import vue from '@vitejs/plugin-vue2'
import PresetEnv from 'postcss-preset-env'
import { visualizer } from 'rollup-plugin-visualizer'
import { defineConfig } from 'vite'
import { viteStaticCopy } from 'vite-plugin-static-copy'
import packageJSON from './package.json' assert { type: 'json' }
const getPlugins = ({ enableVisualizer }: { enableVisualizer: boolean }) => [
commonjs({
include: [/\/node_modules\//],
}),
viteStaticCopy({
targets: [
{
dest: '.',
rename: 'variables.scss',
src: 'source/kotti-style/_variables.scss',
},
],
}),
vue(),
...(enableVisualizer
? [
visualizer({
filename: 'report.sunburst.html',
template: 'sunburst',
}),
visualizer({
filename: 'report.treemap.html',
template: 'treemap',
}),
]
: []),
]
/**
* @see {@link https://vitejs.dev/config/}
*/
export default defineConfig(({ mode }) => {
/**
* @see {@link https://vitejs.dev/guide/env-and-mode.html#node-env-and-modes}
*/
const isProduction = mode === 'production'
const enableVisualizer = ['1', 'true', 'y', 'yes'].includes(
process.env.ENABLE_VISUALIZER?.toLowerCase() ?? '',
)
// eslint-disable-next-line no-console
if (enableVisualizer) console.info('enabling visualizer')
const external = [
...Object.keys(packageJSON.peerDependencies),
...Object.keys(packageJSON.dependencies),
/element-ui/,
/tippy\.js/,
/lodash\/.*/,
/vue\/.*/,
]
return {
build: {
emptyOutDir: false,
lib: {
entry: path.resolve(__dirname, 'source/index.ts'),
fileName: 'kotti-ui',
formats: ['es', 'cjs'],
name: 'KottiUI',
},
minify: isProduction ? 'esbuild' : false,
rollupOptions: {
external,
output: {
exports: 'named',
},
strictDeprecations: true,
},
sourcemap: isProduction ? true : 'inline',
target: ['es2022', 'chrome109', 'firefox109', 'safari15', 'edge109'],
},
css: {
postcss: {
plugins: [PresetEnv()],
},
},
plugins: getPlugins({ enableVisualizer }),
test: {
environment: 'jsdom',
globals: true,
typecheck: {
checker: 'vue-tsc',
},
},
}
})