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

fix(h5): router.base support relative path (#3354)

上级 7f649fbb
......@@ -10,6 +10,7 @@ import {
const defaultRouter = {
mode: 'hash',
base: '/',
assets: 'assets',
}
const defaultAsync = {
......@@ -25,6 +26,9 @@ export function uniManifestJsonPlugin(): Plugin {
return {
name: 'uni:h5-manifest-json',
enforce: 'pre',
configResolved(config) {
defaultRouter.assets = config.build.assetsDir
},
transform(code, id) {
if (!opts.filter(id)) {
return
......
......@@ -28,14 +28,20 @@ function addBase(filePath: string) {
export function getRealPath(filePath: string) {
// 相对路径模式对静态资源路径特殊处理
if (__uniConfig.router!.base === './') {
filePath = filePath.replace(/^\.\/static\//, '/static/')
const { base, assets } = __uniConfig.router!
if (base === './') {
if (
filePath.indexOf('./static/') === 0 ||
(assets && filePath.indexOf('./' + assets + '/') === 0)
) {
filePath = filePath.slice(1)
}
}
if (filePath.indexOf('/') === 0) {
if (filePath.indexOf('//') === 0) {
filePath = 'https:' + filePath
} else {
return addBase(filePath.substr(1))
return addBase(filePath.slice(1))
}
}
// 网络资源或base64
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册