Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I write npm package in CoffeeScript?

I have used CoffeeScript for a while. Now I need to write a npm package, can I write it in CoffeeScript, or I should compile CoffeeScript into JavaScript?

like image 522
Zhe Chen Avatar asked Nov 30 '12 13:11

Zhe Chen


People also ask

Can we use NPM package in JavaScript?

NPM is the default package manager for node. It is used to install, share, and manage javascript packages in a project.

Which command is used to install NPM package?

npm install [<@scope>/]<name>@<version> : Install the specified version of the package.


2 Answers

I'm going to suggest that you write your package in coffeescript, but only publish it in javascript. I do it like this:

  • coffeescript code goes in src
  • code is compiled to lib
  • src is committed to my git repo, lib is in my .gitignore
  • lib is published to npm, src is in my .npmignore
  • the coffee-script package is in my devDependencies

You can take a look at a simple package of mine, refix, for inspiration:

  • https://github.com/linus/refix
  • npm install refix
like image 123
Linus Thiel Avatar answered Sep 28 '22 03:09

Linus Thiel


You can write NPM modules in coffeescript, but in order for them to be usable by JS users they must be compiled to JS before you publish on NPM.

package.json makes this easy with their prepublish script hook which runs the specified script before you publish. Heres an example of a prepublish NPM hook in zombie.js

https://github.com/assaf/zombie/blob/master/package.json#L16

like image 22
Joseph Moniz Avatar answered Sep 28 '22 03:09

Joseph Moniz