Does the released npm package need to be precompiled?

in daily work, you need to develop third-party packages on which sdk, is sent to the company"s private npm repository as a basis. In principle, the package should have at least one reference scheme in umd format and one reference scheme for module. But I encountered some misgivings during the release.
so I"d like to ask you whether the npm package released by
needs to be precompiled using babel. Where do you need to compile if necessary.

several options that come to mind for the time being

1. Compile to es5/es3

use babel to compile the syntax to an environment that es5 recognizes, and to compile transform-runtime into the package.

advantages:
  • does not report an error when it is introduced, so you can be a shopkeeper.
disadvantages:
  • if every sdk is like this, then there are n transform-runtime, giants.
  • because the returned function is also in the form of promise, the referrer still has to add polyfill to use it on an earlier version of the browser.

2. Compile to es6

use babel to compile the syntax of stage0-3 into the syntax confirmed by es6.

advantages:
  • is much smaller without adding transform-runtime, for example, async/await only needs to be translated into generator.
  • it makes sense. "you see, the same is true of the axios library, which requires you to compile a wave of your own.
disadvantages:
  • it"s just that compiling the syntax of stage 0-3 into es6, is a bit like taking off your pants and farting.
  • most developers do not want to change the original babel plug-in configuration of the project, and third-party packages are not compiled by default in the babel configuration.

3. Do not compile at all

pros and cons are similar to compiling to es6.

< hr >

temporary solution:

  • how umd is introduced: min.js in dist is compiled to es5/es3.
  • es is introduced: the main of the npm package points directly to the source code and is compiled by the user.
Dec.14,2021

published npm packages do not need to be precompiled using babel. Where do you need to compile if necessary.

my point is that it depends on the requirements of this package .

  1. whether the current package supports the direct introduction of browser , and if necessary, compile according to the browser version supported by this package .
  2. if you do not support the direct introduction of browser , compile according to the supported node version.
  3. so unless you need to support the old version of node , you don't really need to compile it. If a third party needs support, compile it yourself.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eb251b-23c7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eb251b-23c7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?