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 support for ES6 module import #568

Closed
lpellegr opened this issue Jul 19, 2018 · 11 comments
Closed

Add support for ES6 module import #568

lpellegr opened this issue Jul 19, 2018 · 11 comments

Comments

@lpellegr
Copy link

It seems the library cannot be loaded with module imports on modern browsers.

The purpose would be to allow such imports since JavaScript imports are now available with all major browsers. Including an esm file or adapting existing files in the NPM package to have a default export would allow the following:

import ClipboardJS from 'clipboard';
@lpellegr lpellegr changed the title Add support for ES6 browser import Add support for ES6 module import Jul 19, 2018
@chulkilee
Copy link

BTW I can import clipboard 2.0.1 from TypeScript (moduleResolution=node) and use it

import whatever from 'clipboard';

new whatever('#clipboard');

@lpellegr
Copy link
Author

@chulkilee Thanks but the issue is about importing the library using raw JavaScript, not TypeScript:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import

@chulkilee
Copy link

@lpellegr I know - that's why I said "BTW" :)

I'm also curious what's the current "modern" web-asset packaging which supports both direct import on web browser and webpack - could you add example of such libraries here so that the maintainer can take a look?

@lpellegr
Copy link
Author

My usage is for an app built with Polymer 3 and bundled for differential serving (esm, es6, es5). Examples are the PWA sample apps:

https://polymer.github.io/pwa-starter-kit/building-and-deploying/

There are several different ways to add support for ESM. Several libraries such as momentjs, firebase-js-sdk, etc. have such a support.

@raphaguasta
Copy link

It's not working here too. :(

@LostInBrittany
Copy link

I have just summit a PR to make clipboard.js available as an ES6 module, as I needed it to migrate my granite-clipboard webcomponent to Polymer 3 / lit-element.

I needed to migrate some other @zenorocha libraries before, as clipboard.js has a dependency on select and good-listener, that aren't available as ES6 module yet. I have done PRs to make both of them available as ES6 modules (here for select, here for good-listener) but until they are merged I have published the ES6 modules as @migrate-to-esm/select and @migrate-to-esm/good-listener, and I have made this PR use them dependencies. They will be back to the standard one as soon as it's available.

@akoskm
Copy link

akoskm commented Jul 17, 2019

Is this planned for Clipboard.js 3.0 #516?

@zenorocha
Copy link
Owner

Thanks for your patience on this. Can you confirm that #596 address this problem?

@akoskm
Copy link

akoskm commented Mar 7, 2020

I can't recall what was the problem here. This was a long time ago and we ended up importing the minified version of the library:

import Clipboard from 'clipboard/dist/clipboard.min'

because this was working we didn't spend much time figuring out what's the problem. Now we tried importing:

import Clipboard from 'clipboard'

with version

clipboard@^2.0.4:
  version "2.0.4"
  resolved "https://registry.yarnpkg.com/clipboard/-/clipboard-2.0.4.tgz#836dafd66cf0fea5d71ce5d5b0bf6e958009112d"

and it worked so I have no idea why we used the minified version. 🤷‍♂

@zenorocha
Copy link
Owner

Great news! 🎉 🎉 🎉

@ChiragMoradiya
Copy link

ChiragMoradiya commented Jul 29, 2020

I think this is just a partial work. We have enabled ES6 module for clipboard.js, but it's dependencies 'select' and 'good-listener' aren't still upgraded for ES6 modules.

So, Those dependencies also need to be updated, and it's upgraded version should be used in the clipboard.js for the seamless integration.

Changes similar to https://github.com/zenorocha/clipboard.js/pull/596/files (module.exports is replaced with export default) should be made to the 'select' and 'good-listener' libraries too.

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

7 participants