-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathvite.config.ts
81 lines (77 loc) · 2.22 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
/// <reference types="vitest" />
/// <reference types="vite/client" />
import dts from 'vite-plugin-dts';
import path from 'path';
import Vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import { UserConfig, defineConfig, loadEnv } from 'vite';
import browserslistToEsbuild from 'browserslist-to-esbuild';
import { getBabelOutputPlugin } from '@rollup/plugin-babel';
import pkg from './package.json';
const resolvePath = (pathName: string) => path.resolve(__dirname, pathName);
export default defineConfig(({ mode }: UserConfig ) => {
const env = loadEnv(mode as string, process.cwd(), '');
return {
resolve: {
alias: {
'my-custom-vue3-package': resolvePath('./src/index.ts'),
'my-custom-vue3-package/': resolvePath('../src/'),
},
},
build: {
minify: true,
lib: {
fileName: (type) => {
if (type === 'es') return 'index.mjs';
if (type === 'cjs') return 'index.js';
return 'index.js';
},
entry: resolvePath('src/index.ts'),
formats: ['es', 'cjs'],
},
target: browserslistToEsbuild(),
sourcemap: false,
rollupOptions: {
plugins: [
// https://www.npmjs.com/package/@rollup/plugin-babel
getBabelOutputPlugin({
configFile: path.resolve(__dirname, '.babelrc'),
filename: '.babelrc',
}),
],
output: {
exports: 'named',
},
external: [
...Object.keys(pkg.dependencies), // if exist
...Object.keys(pkg.devDependencies),
...Object.keys(pkg.peerDependencies),
],
},
},
plugins: [
Vue({
// reactivityTransform: true,
}),
vueJsx(),
env?.NO_DTS !== '1'
?
// https://www.npmjs.com/package/vite-plugin-dts
dts({
include: 'src',
exclude: ['src/stories/**/**', '**/*.stories.tsx'],
rollupTypes: true,
afterBuild: () => {
// do something else
},
})
: null,
],
// https://github.com/vitest-dev/vitest
test: {
globals: true,
environment: 'jsdom',
setupFiles: ['./setupTests.ts'],
},
} as UserConfig;
});