← 返回命令列表

Linux command

coffee 命令

网络

复制后可按需替换文件名、目录或参数。

常用示例

Compile a CoffeeScript file

coffee -c [script.coffee]

Compile and output

coffee -c -o [output/] [script.coffee]

Watch and compile

coffee -w -c [script.coffee]

Run a CoffeeScript file

coffee [script.coffee]

Start an interactive REPL

coffee

Evaluate CoffeeScript code

coffee -e "[console.log 'Hello']"

Compile all files

coffee -c [src/]

Print compiled JavaScript

coffee -p [script.coffee]

说明

coffee is the command-line compiler and runtime for CoffeeScript, a programming language that compiles to JavaScript. CoffeeScript provides a cleaner syntax inspired by Ruby and Python, featuring significant whitespace, implicit returns, and syntactic sugar for common patterns. The compiler can output JavaScript files, run CoffeeScript directly, or provide an interactive REPL for experimentation. The watch mode enables live development workflows where files are automatically recompiled when saved. CoffeeScript compiles to readable JavaScript that follows best practices. Source maps allow debugging in the original CoffeeScript even when running the compiled JavaScript. The bare option removes the IIFE wrapper for compatibility with module systems.

参数

-c, --compile
Compile CoffeeScript to JavaScript files.
-o _DIR_, --output _DIR_
Output directory for compiled JavaScript.
-w, --watch
Watch files for changes and recompile.
-p, --print
Print compiled JavaScript to stdout.
-e _CODE_, --eval _CODE_
Evaluate a string of CoffeeScript code.
-b, --bare
Compile without the top-level function safety wrapper.
-m, --map
Generate source maps alongside JavaScript.
-M, --inline-map
Embed source maps within the JavaScript file.
-n, --nodes
Print the parse tree (AST) of the source.
-t, --transpile
Pipe output through Babel for ES5 compatibility.
--no-header
Suppress the "Generated by CoffeeScript" header.
-h, --help
Display help information.
-v, --version
Display version information.

FAQ

What is the coffee command used for?

coffee is the command-line compiler and runtime for CoffeeScript, a programming language that compiles to JavaScript. CoffeeScript provides a cleaner syntax inspired by Ruby and Python, featuring significant whitespace, implicit returns, and syntactic sugar for common patterns. The compiler can output JavaScript files, run CoffeeScript directly, or provide an interactive REPL for experimentation. The watch mode enables live development workflows where files are automatically recompiled when saved. CoffeeScript compiles to readable JavaScript that follows best practices. Source maps allow debugging in the original CoffeeScript even when running the compiled JavaScript. The bare option removes the IIFE wrapper for compatibility with module systems.

How do I run a basic coffee example?

Run `coffee -c [script.coffee]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -c, --compile do in coffee?

Compile CoffeeScript to JavaScript files.