import { defineConfig, type Plugin } from 'vite'
import vue from '@vitejs/plugin-vue'
/** WKWebView 用 file:// 加载时,crossorigin 会导致脚本无法执行、页面空白 */
function stripCrossOriginForIOS(): Plugin {
return {
name: 'strip-crossorigin-ios',
apply: 'build',
enforce: 'post',
transformIndexHtml(html) {
return html.replace(/\s+crossorigin(="[^"]*")?/g, '')
},
}
}
/** iOS 内嵌启动配置:在模块脚本之前注入,避免 file:// 下懒加载 chunk 失败 */
function injectIOSRuntimeBootstrap(): Plugin {
return {
name: 'inject-ios-runtime-bootstrap',
apply: 'build',
transformIndexHtml(html) {
const bootstrap = ``
if (html.includes('__WORDLOOP_RUNTIME__')) return html
const withoutModule = html
.replace(/\s+crossorigin(="[^"]*")?/g, '')
.replace('