mathiasbynens / emoji-regex

A regular expression to match all Emoji-only symbols as per the Unicode Standard.
https://mths.be/emoji-regex
MIT License
1.73k stars 174 forks source link

ES6 import #36

Closed mesqueeb closed 6 years ago

mesqueeb commented 6 years ago

Is it possible to write

import emojiRegex from 'emoji-regex'

instead of

const emojiRegex = require('emoji-regex')

? If so, could you add this to the readme! Cheers!!

mathiasbynens commented 6 years ago

It's not going to work out-of-the-box since this package currently is a CJS module as opposed to a JS module.

It would work if you use tooling that magically translates import to require behind the scenes, but that's a lossy translation.

mesqueeb commented 6 years ago

Have you considered adding a rollup build to provide a ES module next to the CJS module? You can separate both builds in the package.json under module and main. I usually do it like so:

  "main": "dist/index.cjs.js",
  "module": "dist/index.es.js",

If you want I can make a pull request, but everyone has their preferred methods of building.

Looking forward to the future! : )

mathiasbynens commented 6 years ago

Sure, send over that PR! Thanks.

mesqueeb commented 6 years ago

@mathiasbynens I did exactly what I said. : D I used a very basic rollup build. And in the package.json I offered the es6 module under module next to the main which I had set to the commonjs, as this is common practise. ; )

You can build with npm run rollup