-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
53 lines (52 loc) · 1.37 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
// @ts-expect-error 'xx'
import { resolve } from 'node:path'
import { defineConfig } from 'vite'
import solidPlugin from 'vite-plugin-solid'
import dts from 'vite-plugin-dts'
import cssInjectedByJsPlugin from 'vite-plugin-css-injected-by-js'
import { name } from './package.json'
export default defineConfig((env) => {
return {
plugins: [
solidPlugin(),
dts({
rollupTypes: true,
}),
cssInjectedByJsPlugin({
injectCode: (cssCode /* , options */) => {
return `if (!document.head.querySelector('style[data-styled-${name}]')) {
const elementStyle = document.createElement('style')
elementStyle.setAttribute('data-styled-${name}', '')
elementStyle.append(document.createTextNode(${cssCode}))
document.head.append(elementStyle)
}`
},
}),
],
resolve: {
alias: {
'@': resolve('src'),
},
},
server: {
port: 3000,
},
css: {
modules: {
scopeBehaviour: 'local',
generateScopedName:
env.command === 'build'
? 'simcom_[hash:5]'
: '[local]___[hash:base64:5]',
},
},
build: {
lib: {
entry: 'src/main.tsx',
name: 'Simcom',
formats: ['es', 'iife'],
fileName: (format) => `simcom.${format}.js`, // 打包后的文件名
},
},
}
})