mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 10:38:16 +08:00
fix: 修复 sdk 在单页中存在多个版本时渲染异常的问题
This commit is contained in:
parent
9597f79764
commit
2b699bf7e6
@ -8,11 +8,31 @@
|
|||||||
(function (global) {
|
(function (global) {
|
||||||
var require, define;
|
var require, define;
|
||||||
var amis = window.amis || {};
|
var amis = window.amis || {};
|
||||||
|
|
||||||
|
// 获取当前加载脚本的路径,从而推断 sdk 的目录,用于异步加载其他资源
|
||||||
|
// 仅用于 jssdk 场景
|
||||||
|
let host = '';
|
||||||
|
if (document.currentScript && document.currentScript.src) {
|
||||||
|
host = document.currentScript.src.replace(/\/[^\/]*$/, '');
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
throw new Error();
|
||||||
|
} catch (e) {
|
||||||
|
host = (/((?:https?|file):.*?)\n/.test(e.stack) && RegExp.$1)?.replace(
|
||||||
|
/\/[^\/]*$/,
|
||||||
|
''
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
amis['sdk@@versionBasePath'] = host;
|
||||||
|
|
||||||
// 避免重复加载而导致已定义模块丢失
|
// 避免重复加载而导致已定义模块丢失
|
||||||
if (amis.require) {
|
if (amis.require) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
amis.sdkBasePath = host;
|
||||||
|
|
||||||
var head = document.getElementsByTagName('head')[0];
|
var head = document.getElementsByTagName('head')[0];
|
||||||
var loadingMap = {};
|
var loadingMap = {};
|
||||||
var factoryMap = {};
|
var factoryMap = {};
|
||||||
@ -306,23 +326,6 @@
|
|||||||
|
|
||||||
require.timeout = 5000;
|
require.timeout = 5000;
|
||||||
|
|
||||||
// 获取当前加载脚本的路径,从而推断 sdk 的目录,用于异步加载其他资源
|
|
||||||
// 仅用于 jssdk 场景
|
|
||||||
let host = '';
|
|
||||||
if (document.currentScript && document.currentScript.src) {
|
|
||||||
host = document.currentScript.src.replace(/\/[^\/]*$/, '');
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
throw new Error();
|
|
||||||
} catch (e) {
|
|
||||||
host = (/((?:https?|file):.*?)\n/.test(e.stack) && RegExp.$1)?.replace(
|
|
||||||
/\/[^\/]*$/,
|
|
||||||
''
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
amis.sdkBasePath = host;
|
|
||||||
|
|
||||||
amis.require = require;
|
amis.require = require;
|
||||||
amis.define = define;
|
amis.define = define;
|
||||||
window.amis = amis;
|
window.amis = amis;
|
||||||
|
@ -657,7 +657,7 @@ if (fis.project.currentMedia() === 'publish-sdk') {
|
|||||||
/function\sfilterUrl\(url\)\s\{\s*return\s*url;/m,
|
/function\sfilterUrl\(url\)\s\{\s*return\s*url;/m,
|
||||||
function () {
|
function () {
|
||||||
return `function filterUrl(url) {
|
return `function filterUrl(url) {
|
||||||
return amis.sdkBasePath + url.substring(1);`;
|
return amis['sdk@${package.version}BasePath'] + url.substring(1);`;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ var rSourceMap =
|
|||||||
/(?:\/\/\#\s*sourceMappingURL[^\r\n\'\"]*|\/\*\#\s*sourceMappingURL[^\r\n\'\"]*\*\/)(?:\r?\n|$)/gi;
|
/(?:\/\/\#\s*sourceMappingURL[^\r\n\'\"]*|\/\*\#\s*sourceMappingURL[^\r\n\'\"]*\*\/)(?:\r?\n|$)/gi;
|
||||||
var caches = {};
|
var caches = {};
|
||||||
var createResource = fis.require('postpackager-loader/lib/resource.js');
|
var createResource = fis.require('postpackager-loader/lib/resource.js');
|
||||||
|
const package = require('../packages/amis/package.json');
|
||||||
|
|
||||||
function prefixCss(code, prefix) {
|
function prefixCss(code, prefix) {
|
||||||
var cssAst = css.parse(code);
|
var cssAst = css.parse(code);
|
||||||
@ -129,9 +130,9 @@ module.exports = function (ret, pack, settings, opt) {
|
|||||||
${contents.replace(
|
${contents.replace(
|
||||||
/\"url\"\s*\:\s*('|")(\.\/.*?)\1/g,
|
/\"url\"\s*\:\s*('|")(\.\/.*?)\1/g,
|
||||||
function (_, quote, value) {
|
function (_, quote, value) {
|
||||||
return `"url": amis.sdkBasePath + ${quote}${value.substring(
|
return `"url": amis['sdk@${
|
||||||
1
|
package.version
|
||||||
)}${quote}`;
|
}BasePath'] + ${quote}${value.substring(1)}${quote}`;
|
||||||
}
|
}
|
||||||
)}
|
)}
|
||||||
})()`;
|
})()`;
|
||||||
|
Loading…
Reference in New Issue
Block a user