如何将 ES6 编写的模块发布到 NPM? [英] How to publish a module written in ES6 to NPM?

查看:31
本文介绍了如何将 ES6 编写的模块发布到 NPM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正准备向 NPM 发布一个模块,当我考虑在 ES6 中重写它时,既要面向未来,又要学习 ES6.我已经使用 Babel 转译为 ES5,并运行测试.但我不确定如何继续:

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. But I'm not sure how to proceed:

  1. 我是否需要转译并将生成的/out 文件夹发布到 NPM?
  2. 我是否将结果文件夹包含在我的 Github 存储库中?
  3. 或者我是否维护 2 个存储库,一个包含用于 Github 的 ES6 代码 + gulp 脚本,另一个包含用于 NPM 的转译结果 + 测试?

简而言之:我需要采取哪些步骤才能将用 ES6 编写的模块发布到 NPM,同时仍然允许人们浏览/分叉原始代码?

In short: what steps do I need to take to publish a module written in ES6 to NPM, while still allowing people to browse/fork the original code?

推荐答案

目前我看到的模式是将 es6 文件保存在 src 目录中,然后在 npm 的 prepublish 中构建你的东西lib 目录.

The pattern I have seen so far is to keep the es6 files in a src directory and build your stuff in npm's prepublish to the lib directory.

您需要一个 .npmignore 文件,类似于 .gitignore 但忽略 src 而不是 lib.

You will need an .npmignore file, similar to .gitignore but ignoring src instead of lib.

这篇关于如何将 ES6 编写的模块发布到 NPM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆