-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.lib.ts
66 lines (63 loc) · 1.58 KB
/
vite.config.lib.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
import path from 'node:path'
import { defineConfig } from 'vite'
import type { UserConfigExport } from 'vite'
import banner from 'vite-plugin-banner'
import compression from 'vite-plugin-compression'
import cssInjectedByJsPlugin from 'vite-plugin-css-injected-by-js'
import dts from 'vite-plugin-dts'
import { bannerTemplate, camelCaseName, isProduction, shortName } from './env'
const config: UserConfigExport = defineConfig({
root: './',
plugins: [
cssInjectedByJsPlugin(),
banner(bannerTemplate),
compression({
algorithm: 'brotliCompress',
ext: '.gz',
}),
dts({
insertTypesEntry: true,
}),
],
css: {
modules: {
localsConvention: 'camelCase',
scopeBehaviour: 'local',
generateScopedName: isProduction ? '[hash:base64:8]' : 'st_[local]_[hash:base64:5]',
},
},
build: {
outDir: 'dist',
emptyOutDir: true,
lib: {
entry: 'src/js/index.ts',
name: camelCaseName,
formats: ['es', 'cjs', 'umd', 'iife'],
fileName: format => `${shortName}.${format}.min.js`,
},
cssMinify: true,
cssCodeSplit: false,
minify: 'terser',
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true,
},
},
rollupOptions: {
input: {
main: path.resolve(__dirname, 'src/js/index.ts'),
},
output: {
banner: bannerTemplate,
exports: 'named',
inlineDynamicImports: true,
},
},
sourcemap: isProduction ? false : 'inline',
},
resolve: {
extensions: ['.js', '.json', '.ts'],
},
})
export default config