How do I compile coffeescript before publishing to NPM?

做~自己de王妃 提交于 2020-01-05 04:36:07

问题


I wrote a simple module in CoffeeScript, but I want to publish the compiled JavaScript to NPM. I don't want to manually run the coffee command each time, that's too much typing and I'll probably forget and publish stale js every now and then.

I know there's some combination of npm package.json script hooks and CoffeeScript cli arguments that will do the trick, but I forget the particulars. How's it go again?


回答1:


A basic package.json setup for the conventional directory structure looks like

"scripts": {
  "prepublish": "coffee --compile --output lib/ src/"
}

If you also want to compile coffeescript before running tests, you likely want to pull the compilation step out as a reusable script:

"scripts": {
  "pretest": "npm run compile",
  "prepublish": "npm run compile",
  "test": "mocha",
  "compile": "coffee --compile --output lib/ src/"
}


来源:https://stackoverflow.com/questions/26196595/how-do-i-compile-coffeescript-before-publishing-to-npm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!