How do I compile coffeescript before publishing to

2019-08-05 09:46发布

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条回答
你好瞎i
2楼-- · 2019-08-05 10:16

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/"
}
查看更多
登录 后发表回答