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

fix(h5): compatible with relative public path

上级 000d2a9c
...@@ -27,13 +27,13 @@ function urlToRequire (url) { ...@@ -27,13 +27,13 @@ function urlToRequire (url) {
} }
const uriParts = parseUriParts(url) const uriParts = parseUriParts(url)
if (!uriParts.hash) { // fixed by xxxxxx (v3 template中需要加/) if (!uriParts.hash) { // fixed by xxxxxx (v3 template中需要加/)
return `"/"+require("${url}")` return `require("${url}")`
} else { // fixed by xxxxxx (v3 template中需要加/) } else { // fixed by xxxxxx (v3 template中需要加/)
// support uri fragment case by excluding it from // support uri fragment case by excluding it from
// the require and instead appending it as string; // the require and instead appending it as string;
// assuming that the path part is sufficient according to // assuming that the path part is sufficient according to
// the above caseing(t.i. no protocol-auth-host parts expected) // the above caseing(t.i. no protocol-auth-host parts expected)
return `"/"+require("${uriParts.path}") + "${uriParts.hash}"` return `require("${uriParts.path}") + "${uriParts.hash}"`
} }
} }
return returnValue return returnValue
...@@ -66,14 +66,18 @@ function rewrite (attr, name, options) { ...@@ -66,14 +66,18 @@ function rewrite (attr, name, options) {
.replace('"@/', '"/') .replace('"@/', '"/')
.replace('"~@/', '"/') .replace('"~@/', '"/')
} }
if (options.service || options.view || options.h5) { // v3,h5 // v3,h5
const needRequire = options.service || options.view || options.h5
if (needRequire) {
attr.value = urlToRequire(attr.value.slice(1, -1)) attr.value = urlToRequire(attr.value.slice(1, -1))
// h5 且 publicPath 为 ./ (仅生产模式可能为./) if (attr.value.startsWith('require("')) { // require
if ( // v3 需要增加前缀 /
options.h5 && if (options.service || options.view) {
options.publicPath === './' attr.value = `"/"+${attr.value}`
) { } else if (options.h5 && options.publicPath === './') {
attr.value = `(${attr.value}).substr(1)` // h5 且 publicPath 为 ./ (仅生产模式可能为./)
attr.value = `(${attr.value}).substr(1)`
}
} }
} }
return true return true
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册