Skip to content

Es6 default import support #2677

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bobzhang opened this issue Mar 26, 2018 · 5 comments
Closed

Es6 default import support #2677

bobzhang opened this issue Mar 26, 2018 · 5 comments

Comments

@bobzhang
Copy link
Member

bobzhang commented Mar 26, 2018

It seems we already support export default.

export {
   $$default,
   $$default as default
}

See http://exploringjs.com/es6/ch_modules.html

const __default__ = «expression»;
export { __default__ as default }; 

That's what we did for default export

For default import,

external myFunction : unit -> unit = "my-module" [@@bs.default]
let () = myFunction ()

Expect generated ES6 code:

import myFunction from "my-module"
myFunction()

For commonjs

var myModule = require("my-module")
myModule.default ()
@kennetpostigo
Copy link

@bobzhang not sure if this is priority, it is a major factor for the public and internal apps we build at my job with bucklescript but first class support for dynamic imports would be great, there was an issue that @glennsl opened after we discussed this at length on discord: #2364

It was closed because someone made a library to enable dynamic imports in BS but it be nice to have this "embedded" in the bucklescript platform:
https://github.com/kMeillet/bs-dynamic-import/blob/master/src/DynamicImport.re

@kennetpostigo
Copy link

kennetpostigo commented Apr 19, 2018

Heres the spec:
https://github.com/tc39/proposal-dynamic-import

Heres some writing on the feature:

It's been implemented in all major bundlers in the Javascript world and it allows shipping only code that needs to be executed per page, reducing overall js that needs to be loaded & parsed at a time. Making webapps snappier overall.

@bobzhang
Copy link
Member Author

hi @kennetpostigo would you discuss it in another issue, this issue is just for default import, thanks!

@Gregoirevda
Copy link
Contributor

Gregoirevda commented May 3, 2018

@bobzhang would external myFunction : unit -> unit = "my-module" [@@bs.default] fix this issue?
apollographql/reason-apollo#80

@schutm
Copy link

schutm commented Mar 17, 2020

Any progress on this one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants