Deprecated: this repository is no longer maintained, use this instead: https://github.com/uupaa/dynamic-import-polyfill
import()
polyfill
dynamic ES proposal: import()
polyfill for browsers
Prerequisite
browser should support :
Install
copy dynamic-import-polyfill.js
in your script directory
add in <head>
:
<script src="./script/dynamic-import-polyfill.js"></script>
Usage
because import
is a reserved keyword, this polyfill use _import
instead:
_import('module.js').then(() => {
// ... module loaded
})
Module should use nodejs module.exports
syntax:
var data = {
foo: '1',
bar() { return 2 }
}
module.exports = data