|
|
@@ -1,55 +1,57 @@
|
|
|
import { defineConfig, loadEnv } from 'vite'
|
|
|
import vue from '@vitejs/plugin-vue'
|
|
|
import path from 'path'
|
|
|
-
|
|
|
-// 引入@vitejs/plugin-legacy
|
|
|
import legacy from '@vitejs/plugin-legacy'
|
|
|
|
|
|
-// https://vite.dev/config/
|
|
|
export default defineConfig(({ mode }) => {
|
|
|
- // 加载对应模式的环境变量
|
|
|
const env = loadEnv(mode, process.cwd())
|
|
|
return {
|
|
|
plugins: [
|
|
|
+ // 关键调整:适配5+App的WebView(安卓5.0+/iOS 10+)
|
|
|
legacy({
|
|
|
- targets: ['defaults', 'not IE 11']
|
|
|
+ targets: ['Android >= 5.0', 'iOS >= 10'], // 精准适配移动端WebView
|
|
|
+ additionalLegacyPolyfills: ['regenerator-runtime/runtime'], // 补充ES6+兼容
|
|
|
+ renderLegacyChunks: true, // 生成兼容包
|
|
|
+ polyfills: [
|
|
|
+ 'es.symbol',
|
|
|
+ 'es.promise',
|
|
|
+ 'es.array.iterator',
|
|
|
+ 'es.object.assign' // 解决低版本WebView的对象赋值兼容
|
|
|
+ ]
|
|
|
}),
|
|
|
vue({
|
|
|
template: {
|
|
|
compilerOptions: {
|
|
|
- // 告诉Vue这些是原生自定义元素,不需要解析为Vue组件
|
|
|
isCustomElement: (tag) => {
|
|
|
- // Blockly工具箱中使用的标签
|
|
|
return ['block', 'category', 'field', 'shadow', 'value', 'sep', 'label'].includes(tag)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}),
|
|
|
],
|
|
|
- base: './',
|
|
|
+ base: './', // 保留相对路径(核心,不能改)
|
|
|
resolve: {
|
|
|
- // 路径别名配置
|
|
|
alias: {
|
|
|
- '@': path.resolve(__dirname, './src')
|
|
|
+ '@': path.resolve(__dirname, './src') // 保留别名
|
|
|
}
|
|
|
},
|
|
|
server: {
|
|
|
host: '0.0.0.0',
|
|
|
proxy: {
|
|
|
'/admin-api': {
|
|
|
- // 使用加载的环境变量
|
|
|
target: env.VITE_BASE_URL,
|
|
|
changeOrigin: true
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
build: {
|
|
|
- outDir: 'aiWeb',
|
|
|
+ outDir: 'aiWeb', // 保留原有输出目录(打包后生成aiWeb文件夹)
|
|
|
+ target: 'es2015', // 关键:降低编译目标,适配旧WebView
|
|
|
+ assetsDir: 'assets', // 明确静态资源目录
|
|
|
rollupOptions: {
|
|
|
output: {
|
|
|
entryFileNames: `assets/[name]-[hash].js`,
|
|
|
chunkFileNames: `assets/[name]-[hash].js`,
|
|
|
- // 保留原始目录结构
|
|
|
assetFileNames: ({ name }) => {
|
|
|
const extType = name.split('.').pop();
|
|
|
if (/png|jpe?g|gif|svg|webp/i.test(extType)) {
|
|
|
@@ -64,7 +66,14 @@ export default defineConfig(({ mode }) => {
|
|
|
return `assets/[name]-[hash].[ext]`;
|
|
|
}
|
|
|
}
|
|
|
+ },
|
|
|
+ // 可选:关闭压缩(避免低版本WebView解析压缩代码失败)
|
|
|
+ minify: mode === 'production' ? 'terser' : false,
|
|
|
+ terserOptions: {
|
|
|
+ compress: {
|
|
|
+ drop_console: false // 保留控制台日志,方便调试
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-})
|
|
|
+})
|