-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
50 lines (48 loc) · 1.65 KB
/
vite.config.ts
File metadata and controls
50 lines (48 loc) · 1.65 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
48
49
50
/// <reference types="vitest" />
/// <reference types="vite/client" />
import react from '@vitejs/plugin-react-swc'
import { glob } from 'glob'
import { fileURLToPath } from 'node:url'
import path, { resolve } from 'path'
import { visualizer } from 'rollup-plugin-visualizer'
import { defineConfig } from 'vite'
import dts from 'vite-plugin-dts'
import { libInjectCss } from 'vite-plugin-lib-inject-css'
// https://vitejs.dev/config/
export default defineConfig({
test: {
environment: 'jsdom',
globals: true,
root: 'src/'
},
build: {
sourcemap: true,
emptyOutDir: true,
lib: {
entry: resolve(__dirname, './src/index.ts'),
formats: ['es'],
fileName: (format) => `index.${format}.js`,
name: 'demolib'
},
rollupOptions: {
input: Object.fromEntries(
glob
.sync('src/**/*.{ts,tsx}', { ignore: ['src/**/*.d.ts', 'src/**/*.stories.{ts,tsx}', 'src/**/*.test.{ts,tsx}'] })
.map((file: string) => {
const entryName = path.relative('src', file.slice(0, file.length - path.extname(file).length)) // Remove `src/` and file extensions
const entryUrl = fileURLToPath(new URL(file, import.meta.url)) // This expands the relative paths to absolute paths
return [entryName, entryUrl]
})
),
output: {
globals: {
react: 'React'
},
entryFileNames: '[name].js',
assetFileNames: 'assets/[name][extname]'
},
external: ['react', 'react-dom', 'react/jsx-runtime', 'classnames']
}
},
plugins: [react(), libInjectCss(), dts({ rollupTypes: true }), visualizer({ filename: 'rollup-build-size.html' })]
})