-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathvite.config.mts
More file actions
100 lines (95 loc) · 3.25 KB
/
Copy pathvite.config.mts
File metadata and controls
100 lines (95 loc) · 3.25 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
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
90
91
92
93
94
95
96
97
98
99
100
import dts from 'unplugin-dts/vite'
import { isAbsolute } from 'node:path'
import { defineConfig } from 'vitest/config'
import { babel, icons, cssConfig } from 'solidos-toolkit/vite'
import type { UserConfig } from 'vite'
import css from './vite-config/css'
import resolveConfig from './vite-config/resolve'
import stylesConfig from './vite-config/styles'
import { cdnLegacyConfig, cdnConfig } from './vite-config/cdn'
import { discoverComponents, litDecoratorPaths, customElementsTypesPlugin } from './vite-config/components'
const basePlugins = [
css(),
icons(),
customElementsTypesPlugin(),
]
// In watch mode we skip .d.ts generation: mashlib/pivot don't consume
// .d.ts at runtime, and regenerating every declaration on each tick is a
// major source of rebuild chatter (each write cascades into downstream
// webpack rebuilds via the symlinked node_modules).
const isWatch = process.argv.includes('--watch') || process.argv.includes('-w')
function defaultConfig(): UserConfig {
return {
css: cssConfig(),
resolve: resolveConfig,
plugins: [
...basePlugins,
babel({ litDecoratorPaths }),
...(isWatch ? [] : [
dts({
tsconfigPath: 'tsconfig.json',
entryRoot: 'src',
outDirs: ['dist'],
insertTypesEntry: true,
}),
]),
],
build: {
emptyOutDir: false,
sourcemap: true,
lib: {
entry: {
index: 'src/index.ts',
'components/index': 'src/components/index.ts',
...Object.fromEntries(
discoverComponents().map((name) => [
`components/${name}/index`,
`src/components/${name}/index.ts`,
])
),
},
},
rolldownOptions: {
output: [
{
format: 'es',
preserveModules: true,
preserveModulesRoot: 'src',
entryFileNames: '[name].esm.js',
},
{
format: 'cjs',
preserveModules: true,
preserveModulesRoot: 'src',
entryFileNames: '[name].cjs.js',
},
],
external: (id) => {
return !id.startsWith('~icons/')
&& !id.startsWith('@/')
&& !id.startsWith('.')
&& !isAbsolute(id)
},
},
},
test: {
environment: 'jsdom',
setupFiles: ['test/helpers/setup.ts'],
coverage: {
include: ['src/**/*.[jt]s'],
},
},
}
}
export default defineConfig(({ mode }) => {
switch (mode) {
case 'cdn-legacy':
return cdnLegacyConfig(basePlugins)
case 'cdn':
return cdnConfig(basePlugins)
case 'styles':
return stylesConfig()
default:
return defaultConfig()
}
})