-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathvite.config.js
65 lines (61 loc) · 1.46 KB
/
vite.config.js
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
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import copy from 'rollup-plugin-copy';
import jsonfile from 'jsonfile';
import path from 'path';
function editPackageJson() {
return {
name: 'edit-package-json',
closeBundle() {
const file = 'dist/package.json';
jsonfile.readFile(file, (err, obj) => {
if (!err) {
obj.main = 'umd/index.js';
obj.module = 'es/index.mjs';
jsonfile.writeFile(file, obj, { spaces: 2, EOL: '\r\n' });
}
});
},
};
}
const buildLib = {
lib: {
entry: path.resolve(__dirname, 'packages/yugioh-card'),
name: 'YugiohCard',
fileName: format => {
if (format === 'es') {
return `${format}/index.mjs`;
}
return `${format}/index.js`;
},
},
rollupOptions: {
plugins: [
copy({
targets: [
{ src: 'LICENSE', dest: 'dist' },
{ src: 'README.md', dest: 'dist' },
{ src: 'packages/yugioh-card/package.json', dest: 'dist' },
],
hook: 'writeBundle',
}),
editPackageJson(),
],
},
};
const buildWebsite = {
outDir: 'docs',
};
export default defineConfig({
base: './',
plugins: [
vue(),
],
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
},
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'], // 扩展了.vue后缀
},
build: process.argv.includes('lib') ? buildLib : buildWebsite,
});