-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvite.config.ts
107 lines (97 loc) · 2.76 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
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
import { vite as htmlplus } from '@htmlplus/element/bundlers.js';
import { glob } from 'glob';
import path from 'path';
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
import { defineConfig } from 'vite';
import dts from 'vite-plugin-dts';
import { examples } from './examples/plugin';
import plugins from './htmlplus.config';
const DESTINATION = 'dist';
export default defineConfig({
cacheDir: '.cache',
server: {
open: 'src/index.html'
},
resolve: {
alias: {
'@': path.resolve(import.meta.dirname, 'src')
}
},
css: {
preprocessorOptions: {
scss: {
api: 'modern-compiler',
style: 'compressed',
additionalData: [
'src/styles/mixins',
'src/styles/variables',
'src/styles/reset.scss',
]
.map((file) => `@use "${path.resolve(__dirname, file)}" as *;`)
.join('\n')
}
}
},
plugins: [
examples(),
htmlplus(...plugins),
peerDepsExternal(),
dts({
outDir: `${DESTINATION}/types`,
resolvers: [
/**
* This resolver generates `.d.ts` files for each `.tsx` file.
* While this approach is somewhat of a workaround and temporary,
* we are actively seeking a more robust solution.
*/
{
name: 'attach-dynamic-typing',
supports: (id) => id.endsWith('.tsx'),
transform({ root, id, code, program }) {
const sourceFile = program.getSourceFile(id)!;
let output = '';
program.emit(sourceFile, (fileName, contents) => {
output =
contents + code.split('THE FOLLOWING TYPES HAVE BEEN ADDED AUTOMATICALLY').pop() ||
'';
});
return [
{
content: output,
path: path.relative(root, id.replace(/\.tsx?$/, '.d.ts'))
}
];
}
}
]
})
],
build: {
emptyOutDir: false,
minify: false,
lib: {
formats: ['es'],
entry: Object.fromEntries(
glob
.sync(['src/elements/*/*.tsx'], { absolute: true })
.map((file) => ['elements/' + path.basename(file, path.extname(file)), file])
.concat([
['core/config', 'src/config/index.ts'],
['elements/index', 'src/elements/index.ts']
])
)
},
rollupOptions: {
output: {
dir: DESTINATION,
chunkFileNames: `[name].js`,
manualChunks(id) {
const normalized = path.normalize(id).split(path.sep).join('/');
if (normalized.includes('/src/elements/')) return;
if (normalized.includes('signature_pad')) return 'vendors/signature_pad';
return 'core/index';
}
}
}
}
});