-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
89 lines (86 loc) · 2.56 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
78
79
80
81
82
83
84
85
86
87
88
89
import fs from 'node:fs'
import { fileURLToPath, URL } from 'node:url'
import react from '@vitejs/plugin-react'
import { globSync } from 'glob'
import { defineConfig } from 'vite'
import type { LibraryOptions } from 'vite'
import dts from 'vite-plugin-dts'
// https://vitejs.dev/config/
export default defineConfig({
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
css: {
preprocessorOptions: {
scss: {
additionalData: fs.readFileSync('./src/style/index.scss'),
api: 'modern-compiler',
silenceDeprecations: ['mixed-decls', 'import'],
},
},
},
build: {
target: 'es2021',
sourcemap: true,
lib: {
name: 'soda',
formats: ['es'],
fileName: (_format, entryName) => `${entryName}.js`,
entry: inventory(),
},
rollupOptions: {
external: ['react', 'react-dom'],
output: {
banner: `"use client";`,
manualChunks(id, { getModuleInfo }) {
if (id.includes('node_modules')) {
return // id.match(/\/node_modules\/(.[^/]+)\//)[1]
}
if (id.endsWith('.scss') || id.endsWith('.css')) {
return 'style.css'
}
/**
* Seems that vite ignore our options for rollupOptions.treeshake
* so we have to set it here
*/
const info = getModuleInfo(id)
info.moduleSideEffects = false
},
},
},
},
plugins: [
react({
jsxImportSource: '@emotion/react',
babel: {
plugins: ['@emotion/babel-plugin'],
},
}),
dts({
exclude: [
'node_modules/**',
'**/*.stories.*',
'*/documentation/**/*',
],
}),
],
})
/**
* Generate entry for vite to build
*/
function inventory(): LibraryOptions['entry'] {
const entry: LibraryOptions['entry'] = Object.fromEntries(
globSync('src/**/*.{ts,tsx}', {
nodir: true,
ignore: ['**/*.stories.*', '**/*.d.ts', '*/documentation/**/*'],
}).map((name) => {
return [
name.replace(/^src(\/|\\)/, '').replace(/\.(ts|tsx)$/, ''),
name,
]
}),
)
return entry
}