-
Notifications
You must be signed in to change notification settings - Fork 6
/
vite.config.ts
88 lines (83 loc) · 2.08 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
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import { resolve } from 'path';
import { existsSync, readdirSync, lstatSync, rmdirSync, unlinkSync } from 'fs';
// import vueJsx from '@vitejs/plugin-vue-jsx';
import VueMacros from 'unplugin-vue-macros/vite';
emptyDir(resolve(__dirname, 'dist'));
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
VueMacros({
plugins: {
vue: vue(),
//vueJsx: vueJsx()
},
}),
],
build: {
cssCodeSplit: true,
lib: {
// Could also be a dictionary or array of multiple entry points
entry: 'src/entry.ts',
name: 'VueStickyElement',
formats: ['es', 'cjs', 'umd'],
fileName(format) {
let extension = 'js';
if (format === 'es') {
extension = 'm' + extension;
} else if (format === 'cjs') {
extension = 'c' + extension;
}
const fileName = `vue-sticky-element.${format}.${extension}`;
return fileName;
},
},
rollupOptions: {
// make sure to externalize deps that should not be bundled
// into your library
input: {
main: resolve(__dirname, 'src/entry.ts'),
},
external: ['vue', 'v-scroll-threshold'],
output: {
assetFileNames: (assetInfo) => {
if (assetInfo.name === 'entry.css') return 'vue-sticky-element.css';
return assetInfo.name as string;
},
exports: 'named',
globals: {
vue: 'Vue',
},
},
},
},
resolve: {
alias: {
'@': resolve(__dirname, 'src'),
},
},
test: {
globals: true,
environment: 'happy-dom',
coverage: {
provider: 'istanbul',
reportsDirectory: './coverage/',
},
},
});
function emptyDir(dir: string): void {
if (!existsSync(dir)) {
return;
}
for (const file of readdirSync(dir)) {
const abs = resolve(dir, file);
// baseline is Node 12 so can't use rmSync
if (lstatSync(abs).isDirectory()) {
emptyDir(abs);
rmdirSync(abs);
} else {
unlinkSync(abs);
}
}
}