forked from code4history/MaplatTin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
85 lines (82 loc) · 2.12 KB
/
vite.config.ts
File metadata and controls
85 lines (82 loc) · 2.12 KB
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
import { defineConfig } from 'vitest/config';
import dts from 'vite-plugin-dts';
import { resolve } from 'path';
import { readFileSync } from 'fs';
const packageJson = JSON.parse(readFileSync('./package.json', 'utf-8'));
const isPackageBuild = process.env.BUILD_MODE === 'package';
// Plugin to remove .ts extensions from imports
const removeTsExtensions = () => {
return {
name: 'remove-ts-extensions',
transform(code: string, id: string) {
if (id.endsWith('.ts') || id.endsWith('.tsx')) {
// Replace imports with .ts extensions (both ./ and ../ relative paths)
return code.replace(
/from\s+['"](\.\.[/][^'"]+|\.\/[^'"]+)\.ts['"]/g,
'from "$1"'
);
}
return code;
}
};
};
export default defineConfig({
base: isPackageBuild ? '/' : './',
build: isPackageBuild ? {
outDir: 'dist',
emptyOutDir: true,
copyPublicDir: false,
lib: {
entry: resolve(__dirname, 'src/index.ts'),
formats: ['es', 'umd'],
name: 'maplat_transform',
fileName: (format) => {
switch (format) {
case 'es':
return 'maplat_transform.js';
case 'umd':
return 'maplat_transform.umd.js';
default:
return 'maplat_transform.js';
}
}
}
} : {
outDir: 'dist-demo',
emptyOutDir: true,
rollupOptions: {
input: {
index: resolve(__dirname, 'index.html'),
singlemap: resolve(__dirname, 'demo/singlemap.html'),
submaps: resolve(__dirname, 'demo/submaps.html'),
mapsync: resolve(__dirname, 'demo/mapsync.html'),
},
},
},
server: {
open: '/',
},
plugins: [
removeTsExtensions(),
dts({
outDir: 'dist',
exclude: ['tests', 'demo', 'node_modules'],
rollupTypes: true,
tsconfigPath: './tsconfig.json',
logLevel: 'silent'
})
],
test: {
environment: 'jsdom',
globals: true,
setupFiles: ['./tests/setup.ts']
},
resolve: {
alias: {
'@': resolve(__dirname, './src')
}
},
define: {
'import.meta.env.APP_VERSION': JSON.stringify(packageJson.version)
}
});