-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.ts
77 lines (72 loc) · 2.16 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
import { defineConfig } from 'vite';
import dts from 'vite-plugin-dts';
import svgo from 'vite-plugin-svgo';
import { join } from 'node:path';
import pkg from './package.json' assert { type: 'json' };
const external = [
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/dot-notation
...Object.keys(pkg['dependencies'] ?? {}),
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/dot-notation
...Object.keys(pkg['peerDependencies'] ?? {})
];
/** Matches `^DEPENDENCY_NAME($|/)` */
const makeExternalPredicate = (externalArr: string[]) =>
externalArr.length
? (id: string) => new RegExp(`^(${externalArr.join('|')})($|/)`).test(id)
: () => false;
export default defineConfig({
build: {
lib: {
entry: join(__dirname, 'src/index.ts'),
fileName: 'index'
},
rollupOptions: {
external: makeExternalPredicate(external),
output: [
{ format: 'cjs' },
{
format: 'esm',
preserveModules: true,
entryFileNames: '[name].mjs'
}
]
}
},
plugins: [
dts(),
svgo({
multipass: true,
plugins: [
{
name: 'preset-default',
params: {
overrides: {
cleanupIds: false,
removeHiddenElems: false,
removeEmptyText: false,
removeViewBox: false,
removeUnknownsAndDefaults: false // Breaks svg mask by removing fill when it's equals to svg fill
}
}
},
{
name: 'addClassesToSVGElement',
params: { classNames: ['r6data'] }
},
{
name: 'prefixIds',
params: {
prefixClassNames: false,
delim: '__',
prefix: (node, info) => {
const [, file] = info.path?.match(/[/\\]?([^/\\]+)$/) ?? [];
const [fileName] = file.split('.');
if (node.name === 'svg') return 'r6data';
return `r6data__${fileName!}`;
}
}
}
]
})
]
});