-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.mjs
60 lines (57 loc) · 1.57 KB
/
vite.config.mjs
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
import path from 'path';
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import pkg from './package.json';
const makeExternalPredicate = (externalArr) => {
if (externalArr.length === 0) {
return () => false;
}
const pattern = new RegExp(`^(${externalArr.join('|')})($|/)`);
return (id) => pattern.test(id);
};
/** @type {import('vite').UserConfig} */
export default defineConfig({
publicDir: false,
emptyOutDir: true,
plugins: [react()],
esbuild: {
target: ['chrome105', 'safari16'],
},
build: {
minify: false,
target: 'esnext',
lib: {
entry: { lib: path.resolve(__dirname, './src/lib/index.ts') },
name: pkg.name,
formats: ['cjs', 'es'],
fileName: (format, entryName) => {
switch (format) {
case 'cjs':
return `cjs/${entryName}.cjs`;
case 'es':
return `esm/${entryName}.mjs`;
default:
return `${entryName}/${format}`;
}
},
},
rollupOptions: {
// external: [/node_modules/],
external: makeExternalPredicate([
// Handles both dependencies and peer dependencies so we don't have to manually maintain a list
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
]),
output: {
chunkFileNames: '[name].[format]',
exports: 'named',
preserveModulesRoot: 'src/lib',
preserveModules: true,
globals: {
'react': 'React',
'react-dom': 'ReactDOM',
},
},
},
},
});