优化小程序部分
This commit is contained in:
1 parent
727319a6eb
commit
d4e89788c5
46 files changed
+4906
-63
No files matched your search
+19
-1
@@ -3,7 +3,25 @@ import uni from '@dcloudio/vite-plugin-uni'
|
||||
import path from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
const rootDir = path.dirname(fileURLToPath(import.meta.url))
|
||||
// 新版 Vite / uni 编译器会把配置文件预打包成 CJS 加载,此时 import.meta.url 为 undefined,
|
||||
// fileURLToPath(undefined) 会抛 "The path argument must be of type string. Received undefined"。
|
||||
// 这里做兜底:拿不到模块路径时退回 __dirname / 当前工作目录(构建命令均在 uniapp 目录执行)。
|
||||
function resolveRootDir() {
|
||||
try {
|
||||
const url = typeof import.meta !== 'undefined' ? import.meta.url : ''
|
||||
if (url) return path.dirname(fileURLToPath(url))
|
||||
} catch (e) {
|
||||
/* import.meta.url 不可用时继续兜底 */
|
||||
}
|
||||
try {
|
||||
if (typeof __dirname !== 'undefined') return __dirname
|
||||
} catch (e) {
|
||||
/* 忽略 */
|
||||
}
|
||||
return process.cwd()
|
||||
}
|
||||
|
||||
const rootDir = resolveRootDir()
|
||||
|
||||
export default defineConfig({
|
||||
base: '/h5/',
|
||||
|
||||
Reference in new issue
Block a user