forked from altai-ui/qui-max
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
119 lines (114 loc) · 3.28 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
108
109
110
111
112
113
114
115
116
117
118
119
import { writeFileSync, mkdirSync, existsSync } from 'fs';
import { resolve } from 'path';
/* eslint-disable import/no-extraneous-dependencies */
import vue from '@vitejs/plugin-vue';
import copy from 'rollup-plugin-copy';
import sassPlugin from 'rollup-plugin-sass';
import type { IdAndContentObject } from 'rollup-plugin-sass/dist/types';
import sass from 'sass';
import { defineConfig } from 'vite';
import dts from 'vite-plugin-dts';
/* eslint-enable import/no-extraneous-dependencies */
// https://vitejs.dev/config/
export default defineConfig({
resolve: {
alias: [
// @/xxxx => src/xxxx
{
find: /^@\/(.+)/,
replacement: `${resolve(__dirname, 'src')}/$1`
},
// #/xxxx => types/xxxx
{
find: /^#\/(.+)/,
replacement: `${resolve(__dirname, 'types')}/$1`
}
]
},
plugins: [
dts({
staticImport: true,
insertTypesEntry: true,
include: ['src/**/*.ts', 'src/**/*.vue', 'src/**/*.d.ts', 'types/**/*.ts']
}),
vue()
],
build: {
sourcemap: true,
lib: {
entry: resolve(__dirname, 'src/qComponents/index.ts'),
name: 'QuiMax'
},
rollupOptions: {
// make sure to externalize deps that shouldn't be bundled
// into your library
external: ['vue'],
treeshake: true,
output: [
{
format: 'umd',
// Provide global variables to use in the UMD build
// for externalized deps
exports: 'named',
globals: { vue: 'Vue' }
},
{
format: 'es',
entryFileNames: '[name].js',
preserveModules: true
}
],
plugins: [
sassPlugin({
runtime: sass,
output(_: string, styleNodes: IdAndContentObject[]) {
styleNodes.forEach(styleNode => {
const splittedPath = styleNode.id?.split('/') ?? [];
const fileName = splittedPath[splittedPath.length - 1].replace(
'.scss',
'.css'
);
if (!existsSync('dist')) mkdirSync('dist');
if (!existsSync('dist/css')) mkdirSync('dist/css');
if (!existsSync('dist/icons')) mkdirSync('dist/icons');
if (!existsSync('dist/fonts')) mkdirSync('dist/fonts');
let fileDir = 'css';
if ('icons.css'.includes(fileName)) {
fileDir = 'icons';
} else if ('fonts.css'.includes(fileName)) {
fileDir = 'fonts';
}
writeFileSync(
`dist/${fileDir}/${fileName}`,
styleNode?.content ?? ''
);
});
}
}),
copy({
targets: [
{
src: [
'src/fonts/Urbanist-Bold.woff2',
'src/fonts/Urbanist-ExtraBold.woff2',
'src/fonts/Urbanist-Medium.woff2',
'src/fonts/Urbanist-Regular.woff2'
],
dest: 'dist/fonts'
},
{
src: 'src/icons/qicon.woff',
dest: 'dist/icons'
},
{
src: 'src/assets',
dest: 'dist'
}
],
verbose: true,
hook: 'closeBundle'
})
]
}
}
});