-
Notifications
You must be signed in to change notification settings - Fork 49
/
vite.config.js
139 lines (132 loc) · 3.09 KB
/
vite.config.js
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// vite.config.js
import { defineConfig } from 'vite'
import typescript from '@rollup/plugin-typescript'
import terser from '@rollup/plugin-terser'
import { resolve, basename } from 'path'
const createBuildConfig = (entry, outputDir, standalone = false, minify = false) => ({
emptyOutDir: false,
lib: {
entry,
formats: ['es'],
},
rollupOptions: {
output: {
entryFileNames: `${outputDir}/[name].js`,
inlineDynamicImports: standalone,
},
plugins: [typescript()],
},
minify,
})
const createPlugins = (minify = false) => [
typescript(),
...(minify
? [
terser({
format: {
comments: 'all',
},
compress: {
toplevel: true,
passes: 2,
},
mangle: false,
}),
]
: []),
]
export default defineConfig(({ command, mode }) => {
const modularConfig = {
build: {
...createBuildConfig(
{
'sortable.a11y': resolve(__dirname, 'src/sortable.a11y.ts'),
sortSortable: resolve(__dirname, 'src/sortSortable.ts'),
sortableEventListener: resolve(__dirname, 'src/sortableEventListener.ts'),
sortable: resolve(__dirname, 'src/sortable.ts'),
enhanceSortableAccessibility: resolve(__dirname, 'src/enhanceSortableAccessibility.ts'),
},
'esm',
),
// Add declaration file generation
rollupOptions: {
output: {
dir: 'dist/esm',
},
},
},
plugins: [
typescript({
declaration: true,
declarationDir: 'dist/esm',
rootDir: 'src',
}),
...createPlugins(),
],
}
const inlineConfigA11y = {
build: createBuildConfig(
{
'sortable.a11y': resolve(__dirname, 'src/sortable.a11y.ts'),
},
'standalone',
true,
),
plugins: createPlugins(),
}
const inlineConfig = {
build: createBuildConfig(
{
sortable: resolve(__dirname, 'src/sortable.ts'),
},
'standalone',
true,
),
plugins: createPlugins(),
}
const bundledConfig = {
build: {
...createBuildConfig(resolve(__dirname, 'src/sortable.ts'), '', false, true),
rollupOptions: {
output: {
format: 'es',
compact: true,
preserveModules: false,
entryFileNames: `[name].js`,
},
},
},
plugins: createPlugins(true),
esbuild: {
minifyIdentifiers: false,
minify: false,
},
}
const bundledA11yConfig = {
...inlineConfigA11y,
build: {
...inlineConfigA11y.build,
rollupOptions: {
...inlineConfigA11y.build.rollupOptions,
output: {
...inlineConfigA11y.build.rollupOptions.output,
entryFileNames: '[name].js',
},
},
},
}
switch (mode) {
case 'bundle':
return bundledConfig
case 'bundle-a11y':
return bundledA11yConfig
case 'standalone':
return inlineConfig
case 'standalone-a11y':
return inlineConfigA11y
case 'module':
return modularConfig
default:
return bundledConfig
}
})