-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
vite.config.ts
75 lines (71 loc) · 1.96 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
/// <reference types="vitest" />
/// <reference types="vite/client" />
import dts from 'vite-plugin-dts';
import fs from 'fs';
import path from 'path';
import Vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import { defineConfig } from 'vite';
import browserslistToEsbuild from 'browserslist-to-esbuild';
import eslint from 'vite-plugin-eslint';
import pkg from './package.json';
const resolvePath = (pathName: string) => path.resolve(__dirname, pathName);
export default defineConfig({
resolve: { alias: { 'vue3-toastify': resolvePath('./src/index.ts') } },
build: {
target: browserslistToEsbuild(),
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'],
},
// sourcemap: true,
rollupOptions: {
output: { exports: 'named' },
external: [
...Object.keys(pkg.devDependencies),
...Object.keys(pkg.peerDependencies),
],
},
},
plugins: [
Vue(),
vueJsx(),
eslint({
// failOnWarning: false,
// failOnError: false,
emitWarning: true,
emitError: true,
}),
// https://www.npmjs.com/package/vite-plugin-dts
dts({
include: 'src',
rollupTypes: true,
afterBuild() {
try {
const filePath = resolvePath('dist/index.d.ts');
const buffer = fs.readFileSync(filePath);
const content = String(buffer).replace('declare interface ToastPromiseParams', 'export interface ToastPromiseParams');
fs.writeFileSync(filePath, content);
} catch (error) {
//
}
},
}),
],
// https://github.com/vitest-dev/vitest
// @ts-ignore
test: {
globals: true,
environment: 'jsdom',
setupFiles: ['./setupTests.ts'],
// transformMode: {
// web: [/.[tj]sx$/],
// },
},
});