Created
October 29, 2021 08:50
-
-
Save HeGanjie/e8f68df3c79041cc64dd918781c3c648 to your computer and use it in GitHub Desktop.
dynamic import compact chrome 63
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function importCompat(nodeBookModuleUrl: string) { | |
try { | |
// const { default: notebook } = await import(/*webpackIgnore: true*/ nodeBookModuleUrl) | |
// 用 eval 绕过打包逻辑 | |
return await eval(`import('${nodeBookModuleUrl}')`) | |
} catch (e) { | |
// https://github.com/guybedford/es-module-shims#shim-mode-option | |
window.esmsInitOptions = { | |
shimMode: true // default false | |
} as any | |
// 解决 chrome 63 不兼容 import.meta.url 的问题 | |
// @ts-ignore | |
await import('es-module-shims') | |
// 解决兼容性报错 | |
// @ts-ignore | |
await import('polyfill-object.fromentries') | |
return await window.importShim(nodeBookModuleUrl) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment