-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
86 lines (83 loc) · 2.13 KB
/
vite.config.ts
File metadata and controls
86 lines (83 loc) · 2.13 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
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: 'BeatBox', // UMDグローバル変数名
fileName: (format) => {
const baseName = 'beatbox';
switch(format) {
case 'es':
return `${baseName}.js`;
case 'cjs':
return `${baseName}.cjs`;
case 'umd':
return `${baseName}.umd.js`;
default:
return `${baseName}.js`;
}
}
}
} : {
outDir: 'dist',
emptyOutDir: true
},
plugins: [
removeTsExtensions(),
dts({
outDir: 'dist',
exclude: ['tests', 'node_modules'],
rollupTypes: false,
skipDiagnostics: true,
tsconfigPath: './tsconfig.json',
logLevel: 'silent',
insertTypesEntry: true,
staticImport: true,
beforeWriteFile: (filePath, content) => {
const fixedContent = content
.replace(/from ['"](\.[^'"]+)\.ts['"]/g, 'from "$1"')
.replace(/import\(["'](\.[^'"]+)\.ts["']\)/g, 'import("$1")');
return {
filePath,
content: fixedContent
};
}
})
],
test: {
environment: 'jsdom',
globals: true,
setupFiles: ['./tests/setup.ts']
},
resolve: {
alias: {
'@': resolve(__dirname, './src')
}
},
define: {
'import.meta.env.APP_VERSION': JSON.stringify(packageJson.version)
}
});