-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
65 lines (64 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
/// <reference types="vite/client" />
/// <reference types="vitest" />
import path, { resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { globSync } from 'glob'
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import dts from 'vite-plugin-dts'
import { libInjectCss } from 'vite-plugin-lib-inject-css'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
react(),
// https://github.com/vitejs/vite/issues/1579#issuecomment-1483756199
libInjectCss(),
dts({ exclude: ['**/*.stories.tsx', 'src/test', '**/*.test.tsx'] }),
],
build: {
lib: {
entry: resolve(__dirname, 'src/main.ts'),
formats: ['es'],
},
rollupOptions: {
external: ['react', 'react-dom', 'react/jsx-runtime'],
// https://rollupjs.org/configuration-options/#input
input: Object.fromEntries(
globSync(['src/components/**/index.tsx', 'src/main.ts']).map((file) => {
// This remove `src/` as well as the file extension from each
// file, so e.g. src/nested/foo.js becomes nested/foo
const entryName = path.relative(
'src',
file.slice(0, file.length - path.extname(file).length)
)
// This expands the relative paths to absolute paths, so e.g.
// src/nested/foo becomes /project/src/nested/foo.js
const entryUrl = fileURLToPath(new URL(file, import.meta.url))
return [entryName, entryUrl]
})
),
output: {
entryFileNames: '[name].js',
assetFileNames: 'assets/[name][extname]',
globals: {
react: 'React',
'react-dom': 'React-dom',
'react/jsx-runtime': 'react/jsx-runtime',
},
},
},
},
test: {
globals: true,
environment: 'happy-dom',
setupFiles: './src/test/setup.ts',
// you might want to disable it, if you don't have tests that rely on CSS
// since parsing CSS is slow
css: true,
coverage: {
include: ['src/components'],
exclude: ['**/*.stories.tsx'],
reporter: ['text'],
},
},
})