Can I write npm package in CoffeeScript?

后端 未结 5 801
夕颜
夕颜 2020-12-12 11:54

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?

5条回答
  •  轮回少年
    2020-12-12 12:15

    If a lot of your modules have coffee-script in their devDependencies, it's useful to just globally install coffee-script instead of install it for each module (which takes much longer).

    coffee-build is a global version manager for coffee-script.

    Just add these 2 scripts to your package.json:

    {
      "name": "my-coffee-module",
      "scripts": {
        "build": "coffee-build -v 1.11.x -b -o js src",
        "postinstall": "npm run build"
      }
    }
    

    Notice how -v 1.11.x is not an exact version, which allows implicit upgrades.

    The only downfall is that users must npm install -g coffee-build before they can install your module.

提交回复
热议问题