Browse Source

KERNEL-14316 fix:worker polyfill

es6
Treecat 1 year ago
parent
commit
e3bafd8af0
  1. 21
      packages/fineui/src/core/platform/web/jquery/jquery.polyfill.js
  2. 1
      packages/fineui/webpack/webpack.prod.js

21
packages/fineui/src/core/platform/web/jquery/jquery.polyfill.js

@ -2,9 +2,10 @@
* 用于 jquery worker 环境或者 V8 引擎的 polyfill * 用于 jquery worker 环境或者 V8 引擎的 polyfill
*/ */
import { _global } from "@/core/0.foundation"; import { _global } from "@/core/0.foundation";
if (!_global.window) {
_global.window = _global; // const _global = globalThis;
const document = (_global.document = {});
const document = {};
const fakeElement = Object.create(document); const fakeElement = Object.create(document);
Object.assign(document, { Object.assign(document, {
@ -78,4 +79,18 @@ if (!_global.window) {
return "FakeElement"; return "FakeElement";
}, },
}); });
function polyfillProps(key, obj) {
_global[key] = _global[key] || obj;
if (typeof obj === "object") {
try {
Object.assign(_global[key], obj);
} catch(err) {
// _global[key] 可能只有 get 方法
} }
}
}
_global.window = _global;
polyfillProps("XMLHttpRequest", function () {});
polyfillProps("document", document);

1
packages/fineui/webpack/webpack.prod.js

@ -19,6 +19,7 @@ module.exports = merge(common, {
entry: { entry: {
"fineui.min": attachments.fineui, "fineui.min": attachments.fineui,
"fineui.worker.min": attachments.fineuiForWorker, "fineui.worker.min": attachments.fineuiForWorker,
"fineui.worker": attachments.fineuiForWorker
}, },
output: { output: {

Loading…
Cancel
Save