-
Notifications
You must be signed in to change notification settings - Fork 151
/
vite.config.ts
71 lines (67 loc) · 1.81 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
import path from 'node:path';
import * as process from 'process';
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue';
import terser from '@rollup/plugin-terser';
import license from 'rollup-plugin-license';
import { getBabelOutputPlugin } from '@rollup/plugin-babel';
import type { OutputOptions, OutputPluginOption } from 'rollup';
import removeNamedExport from './build/rollup-plugin-remove-named-export';
import packageJSON from './package.json';
const author = typeof packageJSON.author === 'string' ? packageJSON.author : ''; // packageJSON.author.name
export default defineConfig({
root: path.resolve(process.cwd(), './dev'),
plugins: [
removeNamedExport(),
getBabelOutputPlugin({
allowAllFormats: true,
presets: [["@babel/preset-env"]],
}),
vue(),
],
build: {
lib: {
entry: path.resolve(process.cwd(), './src/index.ts'),
},
minify: false,
emptyOutDir: false,
rollupOptions: {
output: [
createOutput({
entryFileNames: 'autofit.js',
}),
createOutput({
entryFileNames: 'autofit.min.js',
plugins: [
terser(),
]
}),
]
}
},
});
function createOutput(options: OutputOptions = {
plugins: [],
entryFileNames: ''
}): OutputOptions {
const plugins = (options?.plugins ?? []) as OutputPluginOption[];
return {
dir: path.resolve(process.cwd(), './'),
entryFileNames: options?.entryFileNames,
format: 'umd',
name: 'autofit',
exports: 'default',
plugins: [
license({
banner: {
commentStyle: 'regular',
content: `${packageJSON.name} v${packageJSON.version}
(c) 2023-present${author ? ` ${author}` : ''}
Released under the MIT License.`,
}
}),
...plugins,
],
...options,
};
}