-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
87 lines (81 loc) · 2.86 KB
/
vite.config.ts
File metadata and controls
87 lines (81 loc) · 2.86 KB
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
/// <reference types="histoire" />
import type { PreRenderedAsset } from 'rollup';
import path from 'node:path';
import { fileURLToPath, URL } from 'node:url';
import vue from '@vitejs/plugin-vue';
import { defineConfig } from 'vite';
import dts from 'vite-plugin-dts';
import { collect, pkg, sty } from './build';
import packageJson from './package.json' with { type: 'json' };
// Collect components and entries
const { components, entries } = collect(path.resolve(__dirname, 'src'));
// https://vitejs.dev/config/
export default defineConfig({
define: {
__MIRU_VERSION__: JSON.stringify(packageJson.version),
__BREAKPOINT_XXS__: JSON.stringify(364),
__BREAKPOINT_XS__: JSON.stringify(576),
__BREAKPOINT_SM__: JSON.stringify(640),
__BREAKPOINT_MD__: JSON.stringify(768),
__BREAKPOINT_LG__: JSON.stringify(1024),
__BREAKPOINT_XL__: JSON.stringify(1280),
__BREAKPOINT_XXL__: JSON.stringify(1536),
},
plugins: [
vue(),
pkg(),
sty(),
dts({
beforeWriteFile(filePath: string, content: string) {
const mainPath = path.resolve(__dirname, 'dist', 'miru.d.ts').replace(/\\/g, '/');
if (filePath.startsWith(mainPath)) {
return {
filePath: filePath.replace('/miru.d.ts', '/index.d.ts'),
content
}
}
const componentsPath = path.resolve(__dirname, 'dist', 'components').replace(/\\/g, '/');
if (filePath.startsWith(componentsPath)) {
return {
filePath: filePath.replace('/components/', '/'),
content
}
}
},
copyDtsFiles: true,
//cleanVueFileName: true,
tsconfigPath: 'tsconfig.types.json'
})
],
build: {
outDir: 'dist',
lib: {
entry: entries,
name: 'miru',
formats: ['es']
},
cssCodeSplit: true,
rollupOptions: {
external: ['vue'],
output: {
assetFileNames(chunkInfo: PreRenderedAsset) {
if (chunkInfo.name) {
let name = chunkInfo.name?.slice(0, -4);
if (name in components) {
return `${components[name]}/${chunkInfo.name}`;
} else {
return '';
}
} else {
return '';
}
},
chunkFileNames: '_shared/[name]-[hash].js',
entryFileNames: '[name].js',
globals: {
vue: 'Vue'
},
},
}
}
});