forked from altcha-org/altcha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.plugins.config.ts
49 lines (46 loc) · 1.13 KB
/
vite.plugins.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
/// <reference types="vitest" />
import { defineConfig, Plugin } from 'vite';
import { basename, join } from 'node:path';
import { writeFile } from 'node:fs/promises';
const input = process.argv[process.argv.length - 1];
function generateDTs(): Plugin {
let name: string = '';
let target: string = '';
return {
name: 'generate-d-ts',
configResolved(config) {
const lib = config.build.lib;
if (lib && lib.entry) {
name = basename(String(lib.entry)).replace('.ts', '');
target = join(config.build.outDir, name + '.d.ts');
}
},
async writeBundle() {
if (target) {
await writeFile(target, `declare module 'altcha/${name}';`);
}
},
};
}
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
generateDTs(),
],
build: {
target: 'modules',
outDir: 'dist_plugins',
minify: 'esbuild',
emptyOutDir: false,
lib: {
entry: input,
fileName: '[name]',
name: '[name]',
formats: ['es', 'umd'],
},
rollupOptions: {},
},
define: {
ALTCHA_VERSION: JSON.stringify(process.env.npm_package_version),
},
});