How to publish a module written in ES6 to NPM?

前端 未结 11 661
自闭症患者
自闭症患者 2020-11-29 15:22

I was about to publish a module to NPM, when I thought about rewriting it in ES6, to both future-proof it, and learn ES6. I\'ve used Babel to transpile to ES5, and run tests

11条回答
  •  青春惊慌失措
    2020-11-29 16:02

    The two criteria of an NPM package is that it is usable with nothing more than a require( 'package' ) and does something software-ish.

    If you fulfill those two requirements, you can do whatever you wish. Even if the module is written in ES6, if the end user doesn't need to know that, I would transpile it for now to get maximum support.

    However, if like koa, your module requires compatibility with users using ES6 features, then perhaps the two package solution would be a better idea.

    Takeaway

    1. Only publish as much code as you need to make require( 'your-package' ) work.
    2. Unless the between ES5 & 6 matters to the user, only publish 1 package. Transpile it if you must.

提交回复
热议问题