What is coffeeify?
The coffeeify npm package is a Browserify transform for CoffeeScript. It allows you to require CoffeeScript files in your Browserify bundle, enabling seamless integration of CoffeeScript into your JavaScript projects.
What are coffeeify's main functionalities?
Transform CoffeeScript to JavaScript
This feature allows you to transform CoffeeScript files into JavaScript using Browserify. The code sample demonstrates how to bundle a CoffeeScript file (`main.coffee`) into a JavaScript file (`bundle.js`) using the coffeeify transform.
const browserify = require('browserify');
const fs = require('fs');
browserify({
entries: ['main.coffee'],
transform: ['coffeeify']
})
.bundle()
.pipe(fs.createWriteStream('bundle.js'));
Integration with Browserify
This feature shows how to integrate coffeeify with Browserify directly. The code sample demonstrates how to bundle a CoffeeScript file (`app.coffee`) into a JavaScript file (`app.bundle.js`) by specifying the `.coffee` extension and using the coffeeify transform.
const browserify = require('browserify');
const coffeeify = require('coffeeify');
const fs = require('fs');
browserify({
entries: ['app.coffee'],
extensions: ['.coffee']
})
.transform(coffeeify)
.bundle()
.pipe(fs.createWriteStream('app.bundle.js'));
Other packages similar to coffeeify
coffeescript
The `coffeescript` package is the official CoffeeScript compiler. It can be used to compile CoffeeScript files into JavaScript. Unlike coffeeify, which is a Browserify transform, `coffeescript` is a standalone compiler that can be used in various build processes.
gulp-coffee
The `gulp-coffee` package is a Gulp plugin for compiling CoffeeScript files. It integrates with the Gulp build system, allowing you to include CoffeeScript compilation in your Gulp tasks. This is different from coffeeify, which is specifically designed for use with Browserify.
grunt-contrib-coffee
The `grunt-contrib-coffee` package is a Grunt plugin for compiling CoffeeScript files. It integrates with the Grunt build system, enabling you to add CoffeeScript compilation to your Grunt tasks. This package is similar to gulp-coffee but is designed for use with Grunt instead of Gulp.
coffeeify
CoffeeScript browserify transform. Mix and match .coffee
and .js
files in the same project.
NOTE: As of version 3.0.0 coffeeify requires CoffeeScript to be installed manually as a peerDependency, also note that the CoffeeScript package has changed name from coffee-script
to coffeescript
.
Example
Given some files written in a mix of js
and coffee
:
foo.coffee:
console.log require './bar.js'
bar.js:
module.exports = require('./baz.coffee')(5)
baz.coffee:
module.exports = (n) -> n ** n
Install coffeeify into your app, and CoffeeScript if you don't have it already:
$ npm install --save-dev coffeeify coffeescript
When you compile your app, just pass -t coffeeify
to browserify:
$ browserify -t coffeeify foo.coffee > bundle.js
$ node bundle.js
3125
You can omit the .coffee
extension from your requires if you add the extension to browserify's module extensions:
module.exports = require('./baz')(5)
$ browserify -t coffeeify --extension=".coffee" foo.coffee > bundle.js
$ node bundle.js
3125
You can also pass options to the CoffeeScript compiler:
$ browserify -t [ coffeeify --bare false --header true ] --extension=".coffee" foo.coffee
..
// Generated by CoffeeScript 1.10.0
(function() {
console.log(require('./bar.js'));
}).call(this);
..
Options
Name | Default | Description |
---|
sourceMap | null | Generate source maps, deteremined from browserify's --debug option if not set. |
bare | true | Omit the (function(){ .. }).call(this); wrapper. |
header | false | Include the // Generated by CoffeeScript <version> header in every file processed. |
When using browserify programatically options can be passed as an object, example:
browserify = require 'browserify'
coffeeify = require 'coffeeify'
bundle = browserify
extensions: ['.coffee']
bundle.transform coffeeify,
bare: false
header: true
bundle.add 'foo.coffee'
bundle.bundle (error, result) ->
throw error if error?
process.stdout.write result
Install
With npm do:
npm install --save-dev coffeeify
CoffeeScript is not installed automatically, so that you can choose what version of CoffeeScript you'd like:
npm install --save-dev coffeescript
License
MIT