-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvite.config.ts
More file actions
100 lines (97 loc) · 2.87 KB
/
vite.config.ts
File metadata and controls
100 lines (97 loc) · 2.87 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { defineConfig } from 'vite';
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, id) {
if (id.endsWith('.ts') || id.endsWith('.tsx')) {
// Replace imports with .ts extensions
return code.replace(
/from\s+['"](\.\/[^'"]+)\.ts['"]/g,
'from "$1"'
);
}
return code;
}
};
};
export default defineConfig({
base: './',
build: isPackageBuild ? {
lib: {
entry: resolve(__dirname, 'src/index.ts'),
formats: ['es', 'cjs', 'umd'],
name: 'Quyuan', // UMD global variable name
fileName: (format) => {
const baseName = 'quyuan'; // C4H naming convention (no prefix)
switch(format) {
case 'es':
return `${baseName}.js`;
case 'cjs':
return `${baseName}.cjs`;
case 'umd':
return `${baseName}.umd.js`;
default:
return `${baseName}.js`;
}
}
},
rollupOptions: {
external: ['lit']
}
} : {
outDir: 'dist',
emptyOutDir: true,
rollupOptions: {
input: {
main: resolve(__dirname, 'index.html'),
leaflet: resolve(__dirname, 'leaflet.html'),
openlayers: resolve(__dirname, 'openlayers.html'),
maplibre: resolve(__dirname, 'maplibre.html'),
'test-media': resolve(__dirname, 'test-media.html'),
'e2e-test': resolve(__dirname, 'e2e-test.html')
},
output: {
entryFileNames: 'assets/[name].[hash].js',
chunkFileNames: 'assets/[name].[hash].js',
assetFileNames: 'assets/[name].[hash][extname]'
}
}
},
plugins: [
removeTsExtensions(),
dts({
outDir: 'dist',
exclude: ['tests', 'node_modules'],
rollupTypes: false, // Avoid type definition merging errors
skipDiagnostics: true,
tsconfigPath: './tsconfig.json',
logLevel: 'silent',
insertTypesEntry: true,
staticImport: true,
beforeWriteFile: (filePath, content) => {
// Remove .ts extensions from imports in d.ts files
const fixedContent = content
.replace(/from ['"](\.[^'"]+)\.ts['"]/g, 'from "$1"')
.replace(/import\(["'](\.[^'"]+)\.ts["']\)/g, 'import("$1")');
return {
filePath,
content: fixedContent
};
}
})
],
resolve: {
alias: {
'@': resolve(__dirname, './src')
}
},
define: {
'import.meta.env.APP_VERSION': JSON.stringify(packageJson.version)
}
});