Skip to content
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

Add ES6 import instead of require() #393

Open
mesqueeb opened this issue Mar 9, 2018 · 6 comments
Open

Add ES6 import instead of require() #393

mesqueeb opened this issue Mar 9, 2018 · 6 comments

Comments

@mesqueeb
Copy link

mesqueeb commented Mar 9, 2018

In the case of NPM, currently the documentation says to:
var WebFont = require('webfontloader')
But i think it'd be great if you could add the ES6 method of importing the library as well!

@kgregory
Copy link

This isn't really an issue. If you think the docs should include:

import WebFont from 'webfontloader';

WebFont.load({
  google: {
    families: ['Droid Sans', 'Droid Serif']
  }
});

You should submit a pull request to add it.

@mesqueeb
Copy link
Author

great! I didn't know the syntax for the import, so couldn't do a PR.

Some libraries require import * as WebFont from 'webfontloader' and some just import WebFont from 'webfontloader'

How did you know which?

@mesqueeb
Copy link
Author

#396

@kgregory
Copy link

Some libraries require import * as WebFont from 'webfontloader' and some just import WebFont from 'webfontloader'

It depends on what is exported. Take a look at this: http://2ality.com/2014/09/es6-modules-final.html

@lpellegr
Copy link

The library does not support module import. When imported in a module using:

import WebFont from 'webfontloader';

you get:

Uncaught SyntaxError: The requested module '../node_modules/webfontloader/webfontloader.js' does not provide an export named 'default'

Indeed, looking at the package, there seems to be no support for ESM. It would be convenient to add such support now that module imports are supported in major browsers.

@andrii-litvinov
Copy link

Trying to use WebFont loader with Polymer. The only import that worked for me was

import * as WebFont from 'webfontloader'

and the use

window.WebFont.load(...);

Which means the imported WebFont is never used and IDE like VS Code suggests removing it.

Would be nice if ES6 import could work the way it supposed to:

import WebFont from 'webfontloader';

WebFont.load(...);

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

No branches or pull requests

4 participants