-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
89 lines (76 loc) · 2.13 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
82
83
84
85
86
87
88
89
import { defineConfig } from "vite";
import url from "node:url";
import { join, resolve } from "node:path";
import { readFileSync } from "node:fs";
import { type Plugin } from 'vite';
import { exec } from 'child_process';
import { nodeBuiltIns } from "./utils/config";
import { normalizePath } from "vite";
import { viteStaticCopy } from 'vite-plugin-static-copy'
import chalk from 'chalk'
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
const pkg = JSON.parse(readFileSync(resolve(__dirname, 'package.json')).toString())
const toCopy = [
join('assets'),
]
const dts: Plugin = {
name: 'dts-generator',
buildEnd: (error?: Error) => {
if (!error) {
return new Promise((res, rej) => {
exec(`tsc --emitDeclarationOnly --outDir ./dist/types`,{
cwd: __dirname
}, async (err, stdout, stderr) => {
console.warn((await chalk).yellow(stdout))
res()
});
});
}
},
};
export default defineConfig({
plugins: [
dts,
viteStaticCopy({
targets: [
{
src: normalizePath(resolve(__dirname, 'package.json')),
dest: "./",
},
// NOTE: All of these are required for now to resolve template builds
...toCopy.map(path => {
return {
src: normalizePath(resolve(__dirname, path)) + '/[!.]*',
dest: join(path),
}
})
],
})
],
build: {
emptyOutDir: false,
target: 'node16',
lib: {
entry: {
main: resolve(__dirname, 'index'),
services: resolve(__dirname, 'services/index'),
config: resolve(__dirname, 'config')
},
name: 'solidarity',
formats: ['es', 'cjs'],
fileName: (format, entryName) => `${entryName}.${format === 'es' ? 'mjs' : 'cjs'}`
},
rollupOptions: {
// output: {
// preserveModules: true,
// },
external: Array.from(new Set([
// Ensure self is handled externally
'@commoners/solidarity',
// User-defined external packages
...Object.keys(pkg.dependencies),
...nodeBuiltIns
])),
},
},
})