Files
esengine/packages/tilemap/vite.config.ts
YHH 107439d70c Feature/runtime cdn and plugin loader (#240)
* feat(ui): 完善 UI 布局系统和编辑器可视化工具

* refactor: 移除 ModuleRegistry,统一使用 PluginManager 插件系统

* fix: 修复 CodeQL 警告并提升测试覆盖率

* refactor: 分离运行时入口点,解决 runtime bundle 包含 React 的问题

* fix(ci): 添加 editor-core 和 editor-runtime 到 CI 依赖构建步骤

* docs: 完善 ServiceContainer 文档,新增 Symbol.for 模式和 @InjectProperty 说明

* fix(ci): 修复 type-check 失败问题

* fix(ci): 修复类型检查失败问题

* fix(ci): 修复类型检查失败问题

* fix(ci): behavior-tree 构建添加 @tauri-apps 外部依赖

* fix(ci): behavior-tree 添加 @tauri-apps/plugin-fs 类型依赖

* fix(ci): platform-web 添加缺失的 behavior-tree 依赖

* fix(lint): 移除正则表达式中不必要的转义字符
2025-11-27 20:42:46 +08:00

101 lines
2.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { defineConfig } from 'vite';
import { resolve } from 'path';
import dts from 'vite-plugin-dts';
import react from '@vitejs/plugin-react';
// 自定义插件:将 CSS 内联到 JS 中
function inlineCSS(): any {
return {
name: 'inline-css',
enforce: 'post' as const,
// 在生成 bundle 时注入 CSS
generateBundle(_options: any, bundle: any) {
const bundleKeys = Object.keys(bundle);
// 找到 CSS 文件
const cssFile = bundleKeys.find(key => key.endsWith('.css'));
if (!cssFile || !bundle[cssFile]) {
return;
}
const cssContent = bundle[cssFile].source;
if (!cssContent) return;
// 找到包含编辑器代码的主要 JS 文件(带 hash 的 chunk
const mainJsFile = bundleKeys.find(key =>
key.endsWith('.js') &&
key.includes('index-') &&
bundle[key].type === 'chunk' &&
bundle[key].code
);
if (mainJsFile && bundle[mainJsFile]) {
const injectCode = `
(function() {
if (typeof document !== 'undefined') {
var style = document.createElement('style');
style.id = 'esengine-tilemap-styles';
if (!document.getElementById(style.id)) {
style.textContent = ${JSON.stringify(cssContent)};
document.head.appendChild(style);
}
}
})();
`;
bundle[mainJsFile].code = injectCode + bundle[mainJsFile].code;
}
// 删除独立的 CSS 文件(已内联)
delete bundle[cssFile];
}
};
}
export default defineConfig({
plugins: [
react(),
dts({
include: ['src'],
outDir: 'dist',
rollupTypes: false
}),
inlineCSS()
],
esbuild: {
jsx: 'automatic',
},
build: {
lib: {
entry: {
index: resolve(__dirname, 'src/index.ts'),
runtime: resolve(__dirname, 'src/runtime.ts'),
'editor/index': resolve(__dirname, 'src/editor/index.ts')
},
formats: ['es'],
fileName: (format, entryName) => `${entryName}.js`
},
rollupOptions: {
external: [
'@esengine/ecs-framework',
'@esengine/ecs-components',
'@esengine/ecs-engine-bindgen',
'@esengine/asset-system',
'@esengine/editor-core',
'react',
'react/jsx-runtime',
'lucide-react',
'zustand',
/^@esengine\//,
/^@tauri-apps\//
],
output: {
exports: 'named',
preserveModules: false
}
},
target: 'es2020',
minify: false,
sourcemap: true
}
});