-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvite.config.ts
63 lines (59 loc) · 1.84 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
import { resolve, join } from 'node:path';
import { existsSync } from 'node:fs';
import { writeFile, rm } from 'node:fs/promises';
import { defineConfig } from 'vite';
import mkcert from 'vite-plugin-mkcert';
import dts from 'vite-plugin-dts';
import tscPaths from 'vite-tsconfig-paths';
const outDir = resolve(__dirname, 'dist');
let port: number;
const getIndexCode = (port: number) => (
`await import('https://localhost:${port}/@vite/client');
export * from 'https://localhost:${port}/src/index.ts';`
);
export default defineConfig({
build: {
minify: false,
rollupOptions: {
output: {
format: 'es',
entryFileNames: 'index.js',
},
preserveEntrySignatures: 'strict',
treeshake: 'smallest',
},
lib: {
entry: resolve(__dirname, 'src/index.ts'),
formats: ['es'],
},
},
publicDir: false,
plugins: [
tscPaths(),
mkcert(),
dts({
entryRoot: './src/',
rollupTypes: true
}),
{
name: 'll-serve',
apply: 'serve',
enforce: 'post',
configureServer(server) {
server.httpServer!.once('listening', async () => {
// @ts-ignore
port = server.httpServer.address()['port'];
const indexJs = join(outDir, 'index.js')
if (existsSync(indexJs)) {
await rm(indexJs);
}
await writeFile(indexJs, getIndexCode(port));
});
},
transform: (code, id) => {
if (/\.(ts|tsx|js|jsx)$/i.test(id)) return;
return code.replace(/\/src\//g, `https://localhost:${port}/src/`)
},
},
]
});