提交 9ccffb9c 编写于 作者: fxy060608's avatar fxy060608

fix(h5): remove import.meta.env.BASE_URL

上级 5fe166f3
import type { Plugin } from 'vite'
import type { Plugin, ResolvedConfig } from 'vite'
import {
defineUniManifestJsonPlugin,
......@@ -23,11 +23,13 @@ const defaultAsync = {
export function uniManifestJsonPlugin(): Plugin {
return defineUniManifestJsonPlugin((opts) => {
let resolvedConfig: ResolvedConfig
return {
name: 'uni:h5-manifest-json',
enforce: 'pre',
configResolved(config) {
defaultRouter.assets = config.build.assetsDir
resolvedConfig = config
},
transform(code, id) {
if (!opts.filter(id)) {
......@@ -35,7 +37,11 @@ export function uniManifestJsonPlugin(): Plugin {
}
const manifest = parseJson(code)
const { debug, h5 } = manifest
const router = { ...defaultRouter, ...((h5 && h5.router) || {}) }
const router = {
...defaultRouter,
...{ base: resolvedConfig.base },
...((h5 && h5.router) || {}),
}
if (!router.base) {
router.base = '/'
}
......
......@@ -875,8 +875,8 @@ var index$C = /* @__PURE__ */ defineBuiltInComponent({
};
}
});
const baseUrl = __IMPORT_META_ENV_BASE_URL__;
function addBase(filePath) {
const { base: baseUrl } = __uniConfig.router;
if (uniShared.addLeadingSlash(filePath).indexOf(baseUrl) === 0) {
return uniShared.addLeadingSlash(filePath);
}
......
......@@ -2013,8 +2013,8 @@ var index$y = /* @__PURE__ */ defineBuiltInComponent({
function findElem(vm) {
return vm.$el;
}
const baseUrl = import.meta.env.BASE_URL;
function addBase(filePath) {
const { base: baseUrl } = __uniConfig.router;
if (addLeadingSlash(filePath).indexOf(baseUrl) === 0) {
return addLeadingSlash(filePath);
}
......
......@@ -17,8 +17,9 @@ export function findElem(vm: ComponentPublicInstance) {
return vm.$el
}
const baseUrl = __IMPORT_META_ENV_BASE_URL__
// const baseUrl = __IMPORT_META_ENV_BASE_URL__
function addBase(filePath: string) {
const { base: baseUrl } = __uniConfig.router!
// filepath可能已经被补充了baseUrl
if (addLeadingSlash(filePath).indexOf(baseUrl) === 0) {
return addLeadingSlash(filePath)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册