diff --git a/packages/webpack-uni-pages-loader/lib/platforms/app-plus/app-config-service.js b/packages/webpack-uni-pages-loader/lib/platforms/app-plus/app-config-service.js index feb833a678cf4f2388ed2bfe759d02f754871007..2a9bb9ab4f18bce5b790f22f7f9e9bad538d8d6c 100644 --- a/packages/webpack-uni-pages-loader/lib/platforms/app-plus/app-config-service.js +++ b/packages/webpack-uni-pages-loader/lib/platforms/app-plus/app-config-service.js @@ -42,7 +42,8 @@ var isReady=false;var onReadyCallbacks=[]; var __uniConfig = ${JSON.stringify(appJson, null)}; var __uniRoutes = ${JSON.stringify(__uniRoutes)}; __uniConfig.onReady=function(callback){if(__uniConfig.ready){callback()}else{onReadyCallbacks.push(callback)}};Object.defineProperty(__uniConfig,"ready",{get:function(){return isReady},set:function(val){isReady=val;if(!isReady){return}const callbacks=onReadyCallbacks.slice(0);onReadyCallbacks.length=0;callbacks.forEach(function(callback){callback()})}}); -service.register("uni-app-config",{create(a,b,c){if(!__uniConfig.viewport){var d=b.weex.config.env.scale,e=b.weex.config.env.deviceWidth,f=Math.ceil(e/d);Object.assign(__uniConfig,{viewport:f,defaultFontSize:Math.round(f/20)})}return{instance:{__uniConfig:__uniConfig,__uniRoutes:__uniRoutes,window:void 0}}}}); +service.register("uni-app-config",{create(a,b,c){if(!__uniConfig.viewport){var d=b.weex.config.env.scale,e=b.weex.config.env.deviceWidth,f=Math.ceil(e/d);Object.assign(__uniConfig,{viewport:f,defaultFontSize:Math.round(f/20)})}return{instance:{__uniConfig:__uniConfig,__uniRoutes:__uniRoutes,window:void 0,global:void 0}}}}); ` } -} +} + diff --git a/src/platforms/h5/helpers/get-real-path.js b/src/platforms/h5/helpers/get-real-path.js index 0b018beca4426037c549aed50facf451b36c1aef..b8c611ce6d03c8679bec1222cd1989e0321c0c1e 100644 --- a/src/platforms/h5/helpers/get-real-path.js +++ b/src/platforms/h5/helpers/get-real-path.js @@ -4,10 +4,17 @@ const SCHEME_RE = /^([a-z-]+:)?\/\//i const DATA_RE = /^data:.*,.*/ function addBase (filePath) { - if (__uniConfig.router.base) { - return __uniConfig.router.base + filePath + const base = __uniConfig.router.base + if (!base) { + return filePath } - return filePath + if (base !== '/') { + // 部分地址已经带了base(如被webpack处理过的资源自动带了publicPath) + if (('/' + filePath).indexOf(base) === 0) { + return '/' + filePath + } + } + return base + filePath } export default function getRealPath (filePath) {