Skip to content

Instantly share code, notes, and snippets.

@HeGanjie
Created October 29, 2021 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HeGanjie/e8f68df3c79041cc64dd918781c3c648 to your computer and use it in GitHub Desktop.
Save HeGanjie/e8f68df3c79041cc64dd918781c3c648 to your computer and use it in GitHub Desktop.
dynamic import compact chrome 63
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