-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
83 lines (75 loc) · 2.18 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
import fs from 'fs'
import path from 'path'
import { defineConfig } from 'vite'
import stringHash from 'string-hash'
// This file will be auto-generated
const components = path.resolve(__dirname, 'lib/components.js')
export default defineConfig(async ({ mode }) => {
// Watch only on dev mode, ignoring auto-generated files
const watch = mode === 'dev' && {
exclude: [components]
}
return {
build: {
watch,
sourcemap: true,
lib: {
entry: {
components,
jsx: path.resolve(__dirname, 'lib/jsx/index.js'),
state: path.resolve(__dirname, 'lib/state/index.js')
},
name: '@tooooools/ui'
}
},
plugins: [
{
name: 'build-components-index',
apply: 'build',
buildStart: () => {
console.log('\ngenerating components/index.js...\n')
const dir = path.resolve(__dirname, 'lib/components')
fs.writeFileSync(
components,
[
'// Auto-generated by the build-components-index plugin',
...fs.readdirSync(dir).map(filename =>
/.*.jsx/.test(filename) &&
`export { default as ${path.parse(filename).name} } from './components/${filename}'`
).filter(Boolean),
''
].join('\n'),
'utf8'
)
}
}
],
css: {
devSourcemap: true,
preprocessorOptions: {
scss: {
additionalData: `
@use 'lib/style/_helpers' as *;
@import 'lib/style/reset';
@import 'lib/style/variables';
@import 'lib/style/mixins';
`
}
},
modules: {
generateScopedName: function (name, filename, css) {
// Do not mangle state classnames
if (/^(is-|has-)/.test(name)) return name
const i = css.indexOf(`.${name}`)
const lineNumber = css.substr(0, i).split(/[\r\n]/).length
const hash = stringHash(css).toString(36).substr(0, 5)
return `ui-${name}-${hash}${lineNumber}`
}
}
},
esbuild: {
jsxInject: "import h from '/lib/jsx/h'",
jsxFactory: 'h'
}
}
})