-
Notifications
You must be signed in to change notification settings - Fork 22
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
Have one distinct build file per language #40
Conversation
The original idea was if you want a portion of it, you would need to use WebPack (or equivalent) yourself. I did this to keep the NPM package size small and to allow downstream users flexibility. This PR does not allow the selective inclusion but really just pre-packages each language individually, as you can already selectively include languages. Do you not run WebPack in your own project? |
Thanks for your feedback. Yes, this PR does not allow the selective inclusion but really just pre-packages each language individually. (I use rollup) I'm unsure about how I could remove unuseful stuff from an already precompiled package. Tree shake, probably, won't work. I'll test tomorrow. |
You can easily include any of the language files directly. import Num2Word from 'n2words/lib/i18n/EN.mjs'; Edit: Are you perhaps having trouble importing in a CommonJS environment? |
n2wordsWrapper.js const n2words = require('../../../node_modules/n2words/lib/i18n/EN.mjs');
exports.n2wordsEn = function (val) {
return n2words(val, { lang: 'en' });
}; and include this file in my .ts files (I don't like it: the path is weird in my mono repo)
Isn't all that a huge mess? What for? Just including the proper .js in dist should solve it all. |
You can use modules in TypeScript - https://www.typescriptlang.org/docs/handbook/modules.html As for the invalid reference, it's because of the context |
I see Edit: I understand you already found a workaround, however undesirable. |
If you can setup a repo with the minimal amount necessary to reproduce the issue I'd be glad to help further. |
Thanks for your suggestions. What I do currently:
and I end up with smaller packages - which was my sole target. I will switch to mainstream n2words repo back once I can import easily mjs files in TypeScript. I don't except to do any modifications of n2words except this packaging part. Feel free to accept or deny the PR. I can live with the fork (even if I will have to sync it manually with the main repo). |
I guess that would work for you, but I don't believe your issue begins at this package. There should be absolutely no need to consume the bundled versions if you are using a bundler in your own project. The vanilla (source) code runs on latest Node and Browsers with no modification. We run even the tests on source files in Node as-is. As for providing pre-built individual languages that we bundle and polyfill which is probably only needed for older browsers is up to @forzagreen IMHO you should build for your specific target environments and steer away from consuming polyfilled scripts. |
I agree with the way of packaging. |
I believe you are on to something. We should give concern to CommonJS users wanting only specific languages. Currently, our build process only creates a concatenated script that includes every language. Interoperability between CJS and ESM is still murky water, and I will need to refine it. I will look at improving the dual environment package within the next couple months as well. |
I believe this to be the source of truth - https://nodejs.org/api/esm.html#esm_interoperability_with_commonjs Correct me if Node doesn't set the standards. I found this in the current documentation: as well as Yes, they doubly used "use". LOL Futher more, I will create a vanilla package in CJS and try to include the ESM languages directly. If I encounter any issues, I will figure out a solution and make it known. |
thanks, I'm eager to see the solution (and integrate it) |
I successfully imported the ESM module via CommonJS with the // Dynamic Import
import('n2words/lib/n2words.mjs').then(n2words => {
// Available via "default" function
console.log(n2words.default(100));
}).catch(err => {
// Catch dynamic import error
console.error(err);
}); |
I have a very, very small package written in TypeScript and using n2words - actually only the Italian locale. npm package is https://www.npmjs.com/package/italian-ordinals-cardinals I just can't make it work using standard version of n2words. |
Unfortunately, I had to use a forked version of TypeScript to resolve the issues it has with |
This should be closed IMHO |
@ludans, There has been recently some work related to this topic by @TylerVigario |
thanks for the notification |
Some applications (well, mine actually) only require some languages.
Importing all of them for browser use is too heavy (93kb), while 1 file per language is lighter (30 to 40kb).
This PR builds, along the complete file, 1 file per language in dist/.