forked from json5/json5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
68 lines (65 loc) · 1.54 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
import { join, resolve } from 'path';
import { defineConfig } from 'vitest/config';
import terser from '@rollup/plugin-terser';
const EXTENSIONS: Record<string, string> = {
es: 'mjs',
cjs: 'cjs',
};
export default defineConfig(({ mode }) => {
if (mode === 'cli') {
return {
build: {
emptyOutDir: false,
sourcemap: false,
minify: false,
lib: {
entry: 'src/cli.ts',
formats: ['es'],
fileName: () => 'cli.mjs',
},
rollupOptions: {
external: ['path', 'fs', './index'],
output: {
paths: {
[resolve('./src/index')]: './es/index.mjs'
}
}
},
},
};
}
return {
build: {
emptyOutDir: !process.env.MINIFY,
sourcemap: !!process.env.MINIFY,
minify: !!process.env.MINIFY,
lib: {
entry: 'src/',
name: 'JSON11',
formats: ['umd', 'cjs', 'es'],
fileName: (format) => {
return join(format, `index${process.env.MINIFY ? '.min' : ''}.${EXTENSIONS[format] || 'js'}`);
},
},
rollupOptions: {
external: ['path', 'fs'],
plugins: [
process.env.MINIFY
? terser({
ecma: 2020,
})
: undefined,
],
},
},
test: {
coverage: {
provider: 'istanbul',
reporter: ['text', 'html'],
reportsDirectory: './.coverage',
include: ['src/**/*.ts'],
exclude: ['src/cli.ts'],
},
},
};
});