node-i18n-iso-countries
node-i18n-iso-countries copied to clipboard
Add rollup & support ES modules
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.
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
@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.
Hey @hansottowirtz, can you update the PR with latest changes from master?
@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 https://github.com/microsoft/TypeScript/issues/33079.
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.
installation fails on Windows: `npm ERR! > [email protected] 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.
any plans to merge this into master at some point?
@bschnabel I don't think that the work here is done. More like a WIP. Correct me if I'm wrong @hansottowirtz ?