F
F
FLighter2019-11-09 15:26:07
JavaScript
FLighter, 2019-11-09 15:26:07

What should be the final npm package file?

Good day!
I published an npm package which is a class with no dependencies that does something. Sources in TypeScript, with the help of babel and rollup, the module is assembled into several options, the main one after installation via npm is the non-minified UMD ESNext (that is, not converted code to ES5). I chose this option because core-js will greatly bloat the module when converted, from 6kb to 20kb when minified, from 20kb to 70kb without minification. That. shifting the task of transpiling to the user. But at the same time, I know that many users do not convert modules from node_modules , then my code will remain in ESNext and may not work.
Actually, the question is:should the final file of the module be already converted and minified, or should the conversion be done by the user using assemblers?
Why the first option confuses me: there is a user who uses two converted/minified modules. These two modules use .includes() which will be transpiled into some function. It turns out that the code will be bloated, since both modules use N identical converters, and the same webpack is unlikely to be able to find them and take them out separately for both modules.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Ruslan Lopatin, 2019-11-09
@flighter7

No need to stuff extra dependencies like core-js into the final file. There should be only the library code. Dependencies the consumer of your package will add and so. Just add them to peerDependencies.
rollup has an external option for this.
To prevent helper functions from being added to the final file, the options "importHelpers": true, "noEmitHelpers": true must be added to tsconfig, and depending on the package, add tslib.
If this is not done, then it may happen that the same dependencies are added to the final application several times.

G
grinat, 2019-11-09
@grinat

It should already be minified, this task is shifted to the user only by dead people, because. create react app and the like do not require custom configs. For the second, see lodash, for example, you can drag everything there, or only a separate submodule.
Yes, and I do not advise using rollup, it's shit with a bunch of problems and a rather rotten community.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question