未验证 提交 a448af45 编写于 作者: X xlfsummer 提交者: GitHub

feat: h5.router.base 增加相对路径支持

优化了 indexOf/substr 的写法,使用 startsWith/endsWith 更加语义化
上级 400fce47
......@@ -60,10 +60,10 @@ function getH5Options (manifestJson) {
let base = h5.router.base
if (base.indexOf('/') !== 0) {
if (!base.startsWith('/') && !base.startsWith('./')) {
base = '/' + base
}
if (base.substr(-1) !== '/') {
if (!base.endsWith('/')) {
base = base + '/'
}
......@@ -72,11 +72,17 @@ function getH5Options (manifestJson) {
if (process.env.NODE_ENV === 'production') { // 生产模式,启用 publicPath
h5.publicPath = h5.publicPath || base
if (h5.publicPath.substr(-1) !== '/') {
if (!h5.publicPath.endsWith('/')) {
h5.publicPath = h5.publicPath + '/'
}
} else { // 其他模式,启用 base
h5.publicPath = base
if(base.startsWith('./')) {
// 在开发模式, publicPath 如果为 './' webpack-dev-server 匹配文件时会失败
h5.publicPath = base.substr(1)
} else {
h5.publicPath = base
}
}
if (process.env.UNI_SUB_PLATFORM === 'mp-360') {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册