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

Export as es module #74

Closed
tlouisse opened this issue Jan 24, 2022 · 11 comments · Fixed by #77
Closed

Export as es module #74

tlouisse opened this issue Jan 24, 2022 · 11 comments · Fixed by #77
Labels

Comments

@tlouisse
Copy link
Contributor

tlouisse commented Jan 24, 2022

Hi,

Thanks for making this great package. It seems to be better than the original google-libphonenumber, both in terms of performance and developer experience.

What I was wondering, would it be possible to add an esm output that allows for running this inside the browser as well?

If appreciated, I could do a PR for this. I have a local version running of this, that could be added to the current gulp task.
The build output could then be added as an export map:

"exports": {
  "./": {
    "require": "./index.js",
    "default": "./index-esm.mjs",
  }
}

In this way, I could use it in a browser context as:

import PhoneNumber from 'awesome-phonenumber';

and for NodeJS/commonjs it would stay as is:

const PhoneNumber = require( 'awesome-phonenumber' );
@grantila
Copy link
Owner

I'm not sure I follow; what makes this not work in a browser today? Using import should work just fine (at least if using a bundler like webpack). The export should work in both cases. Or do you mean without a bundler altogether?

@grantila
Copy link
Owner

grantila commented Feb 1, 2022

Regardless @tlouisse, feel free to make a PR and let me have a look

@tlouisse
Copy link
Contributor Author

tlouisse commented Feb 1, 2022

Hi, thanks for the reply. I mean without a bundler indeed. I want to use it inside a web component (an input that validates/formats phone numbers). This web component is shipped as its own package and should be able to work without a "build step".

You can expect a pull request in the coming weeks when I'm picking this up again 👍

@vrumjantsev
Copy link

@tlouisse hi, any update on that?

@tlouisse
Copy link
Contributor Author

@tlouisse hi, any update on that?

Hi, I will try to look into it in the coming days :)

@tlouisse
Copy link
Contributor Author

@grantila I added the pr for this: #77

Let me know if this works for you!

@tlouisse
Copy link
Contributor Author

tlouisse commented May 4, 2022

@grantila any update on this?

@grantila
Copy link
Owner

grantila commented May 8, 2022

I had the idea of changing the API while doing this, and everything ended up a lot more complicated, e.g. rollup didn't handle named exports well (from the closure-compiled output). But it's all finally working well, thanks for the work on this!

@grantila
Copy link
Owner

grantila commented May 8, 2022

For reference of the API change; the new construction is deprecated, and the library now exports only named functions, making it more functional and easy to compose.
Under the hood, the old API is still there, but removed from the TypeScript typings.

@github-actions
Copy link

github-actions bot commented May 8, 2022

🎉 This issue has been resolved in version 3.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@tlouisse
Copy link
Contributor Author

tlouisse commented May 9, 2022

Nice! Thanks a lot @grantila

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

Successfully merging a pull request may close this issue.

3 participants