Files
bim_engine/vite.config.ts

93 lines
2.7 KiB
TypeScript
Raw Normal View History

2025-12-03 12:00:46 +08:00
import { defineConfig } from 'vite';
import dts from 'vite-plugin-dts';
import { resolve } from 'path';
import cssInjectedByJs from 'vite-plugin-css-injected-by-js';
import pkg from './package.json';
2026-04-21 15:07:36 +08:00
import type { Plugin } from 'rollup';
/**
* webpack 5 / Next.js
*
* Vite lib ESM data URL
* `new URL("data:...", import.meta.url).href`
*
* Next.js 14 (webpack 5) ESM webpack 5 asset module
* `new URL(..., import.meta.url)` Next.js
* `asset/inline` `filename` generator schema
* validation
* "generator has an unknown property 'filename'. These properties are valid:
* object { dataUrl? }"
*
* `new URL("data:...", import.meta.url).href`
* data URL webpack asset module
*
* data URL import.meta.url base
*/
const fixWebpack5CompatPlugin = (): Plugin => ({
name: 'fix-webpack5-compat',
renderChunk(code) {
// 匹配 new URL("data:...", import.meta.url).href 或 new URL('data:...', import.meta.url).href
const fixed = code.replace(
/new URL\(["'](data:[^"']+)["'],\s*import\.meta\.url\)\.href/g,
'"$1"'
);
if (fixed !== code) {
console.log('[fix-webpack5-compat] Replaced new URL(data:..., import.meta.url) with direct data URL');
}
return {
code: fixed,
map: null,
};
},
});
2025-12-03 12:00:46 +08:00
2025-12-16 11:57:44 +08:00
export default defineConfig(() => {
2025-12-03 12:00:46 +08:00
return {
plugins: [
// 移除 Vue 插件
dts({
include: ['src'],
2025-12-04 18:39:07 +08:00
exclude: [
2025-12-16 11:57:44 +08:00
'src/**/*.es.js',
2025-12-04 18:39:07 +08:00
'**/*.es.js'
],
rollupTypes: false,
2025-12-04 18:39:07 +08:00
logLevel: 'warn', // 只显示警告和错误
2025-12-03 12:00:46 +08:00
}),
cssInjectedByJs()
],
2025-12-04 18:39:07 +08:00
// 开发服务器配置
server: {
port: 3000,
host: '0.0.0.0',
open: '/demo/index.html',
allowedHosts: true,
2025-12-04 18:39:07 +08:00
},
define: {
__APP_VERSION__: JSON.stringify(pkg.version),
},
2025-12-03 12:00:46 +08:00
build: {
lib: {
entry: resolve(__dirname, 'src/index.ts'),
name: 'IflowEngine',
fileName: (format) => `iflow-engine.${format}.js`,
2025-12-03 12:00:46 +08:00
},
rollupOptions: {
2026-03-26 09:34:21 +08:00
external: ['opentype.js'],
2025-12-03 12:00:46 +08:00
output: {
2026-03-26 09:34:21 +08:00
globals: {
'opentype.js': '{}',
},
// 禁用代码分割,将所有代码打包到一个文件
inlineDynamicImports: true,
2025-12-03 12:00:46 +08:00
},
2026-04-21 15:07:36 +08:00
plugins: [
fixWebpack5CompatPlugin(),
],
2025-12-03 12:00:46 +08:00
},
sourcemap: true,
emptyOutDir: true,
},
};
2025-12-16 11:57:44 +08:00
});