Repository navigation
Expand file tree
/
Copy pathvite.config.ts
More file actions
47 lines (44 loc) · 1.46 KB
/
Copy pathvite.config.ts
File metadata and controls
47 lines (44 loc) · 1.46 KB
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
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import path from 'path'
import pkg from './package.json'
const externalPackages = [
...Object.keys(pkg.peerDependencies),
...Object.keys(pkg.dependencies),
]
// Subpaths must match: the bundle reaches for 'react/jsx-runtime' and '@hookform/resolvers/zod',
// which are not package names. Stylesheets must not: src imports react-phone-input-2's css, and
// externalising it drops 45 kB out of the emitted stylesheet and leaves a require() of a .css
// file in the cjs build.
const isExternal = (id: string) =>
!id.endsWith('.css') &&
externalPackages.some((name) => id === name || id.startsWith(`${name}/`))
// Library build for src/. The dev playground uses dev/vite.config.ts.
export default defineConfig({
plugins: [react()],
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
},
},
css: {
preprocessorOptions: {
scss: {
api: 'modern-compiler',
},
},
},
build: {
lib: {
entry: {
index: path.resolve(__dirname, 'src/index.ts'),
mantine: path.resolve(__dirname, 'src/adapters/mantine/index.ts'),
},
formats: ['es', 'cjs'],
fileName: (format, entryName) => `${entryName}.${format === 'es' ? 'mjs' : 'cjs'}`,
},
rollupOptions: {
external: isExternal,
},
},
})