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 rollup & support ES modules #188

Closed

Conversation

hansottowirtz
Copy link

@hansottowirtz hansottowirtz commented Jul 7, 2020

This is a WIP. Closes #186.

It adds Rollup and converts the source files to ES modules. When using ES modules in Node, it is not possible to import JSON files. Rollup therefore compiles the .json files to .mjs and .js files. codes.json is bundled in every distributed file, and entry-node.mjs bundles all languages into one file.

It makes it possible to do the following (from Node 13+, Webpack 5):

import en from "i18n-iso-countries/langs/en";
import countries from "i18n-iso-countries";
countries.registerLocale(countries);

or

import entryNode from "i18n-iso-countries/bundled";

I'm using it on our Angular 10 website and it works (as Angular CLI uses Webpack 4, I still need to import i18n-iso-countries/dist/langs/en).

Anyone can install this branch with NPM by running the command below. I also added a prepare script, which builds the code if the package is being installed from Github.

npm i hansottowirtz/node-i18n-iso-countries#add-rollup-support-esm

More testing is needed before merging this PR, with multiple node versions and with Webpack 5.

@KingDarBoja
Copy link
Contributor

KingDarBoja commented Aug 19, 2020

Couldn't find your package on npm, can you share a link? Also, there is a npm package which is a Angular wrapper for this library: https://www.npmjs.com/package/@ngx-countries/countries

@hansottowirtz
Copy link
Author

@KingDarBoja I didn't publish a package, but you can use

"i18n-iso-countries": "github:hansottowirtz/node-i18n-iso-countries#add-rollup-support-esm"

in package.json.

@KingDarBoja
Copy link
Contributor

Hey @hansottowirtz, can you update the PR with latest changes from master?

@hansottowirtz
Copy link
Author

@KingDarBoja done 🙂
I also added typings for the dist/langs/*.mjs files. These typings aren't resolved yet when using the exports field due to microsoft/TypeScript#33079.

@hansottowirtz
Copy link
Author

hansottowirtz commented Nov 24, 2020

It seems like

require('i18n-iso-countries/langs/nl')

only started working somewhere after Node 14.5 (14.15 confirmed working). I added the legacy "./dist/": "./dist/" syntax to the exports field in order to make it work in older versions of Node as well (legacy because now a * is required). They can use

require('i18n-iso-countries/dist/langs/nl.json')

and this syntax will also work in later versions of Node.

@danilofuchs danilofuchs mentioned this pull request Dec 12, 2020
8 tasks
@manzonif
Copy link

installation fails on Windows:
`npm ERR! > i18n-iso-countries@6.2.2 build C:\Users\UserX\AppData\Local\npm-cache_cacache\tmp\git-clone-71f5291a

npm ERR! > make build

npm ERR! /usr/bin/bash: make: command not found`

And doesn't work with yarn.

@bschnabel
Copy link

any plans to merge this into master at some point?

@michaelwittig
Copy link
Owner

@bschnabel I don't think that the work here is done. More like a WIP. Correct me if I'm wrong @hansottowirtz ?

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

Successfully merging this pull request may close these issues.

Does not work well with Angular 10
5 participants