简体   繁体   English

Node.js:使用CoffeeScript创建一个Express项目

[英]Node.js: Create an Express project using CoffeeScript

When I run express app_name, expressjs creates all the folders and files needed. 当我运行express app_name时,expressjs会创建所需的所有文件夹和文件。 I'm wondering if there's a way to do the same but instead of creating the app.js in JS, it creates in CoffeeScript. 我想知道是否有办法做同样的事情,而不是在JS中创建app.js,它在CoffeeScript中创建。

Thanks 谢谢

Try this: https://github.com/twilson63/express-coffee 试试这个: https//github.com/twilson63/express-coffee

express-coffee is a template or boiler-plate to get started writing express web applications in CoffeeScript. express-coffee是开始在CoffeeScript中编写快速Web应用程序的模板或样板。 It comes ready to go with base setup for an Express Web App. 它随时可用于Express Web App的基本设置。 It includes a Cakefile that lets you build, spec, and watch your coffeescript as you develop. 它包含一个Cakefile,可让您在开发时构建,规范和观察您的coffeescript。 You hack in the src folder and run cake build to build you server files, write your mocha in your test folder and run cake test or spec to run your test suite. 你破解src文件夹并运行cake build来构建你的服务器文件,在你的测试文件夹中编写你的mocha并运行cake test或spec来运行你的测试套件。 Create your jade views in the views folder and put your public assets in the public folder... 在views文件夹中创建您的jade视图,并将您的公共资源放在公用文件夹中...

You may want to check out skeleton . 你可能想看看骨架 I also created frappe , which is similar but tweaked for my taste. 我也创造了冰沙 ,这是类似的,但根据我的口味调整。

I don't think there's a command-line tool to do this, but there are plenty of template projects you could start from. 我认为没有一个命令行工具可以做到这一点,但是你可以从很多模板项目开始。 In particular, I'd recommend sstephenson's node-coffee-project . 特别是,我推荐sstephenson的node-coffee-project It's not Express specific, but you can easily throw Express into the package.json and create a src/app.coffee file that looks something like 它不是Express特定的,但您可以轻松地将Express抛入package.json并创建一个src/app.coffee文件

express = require 'express'
app = express.createServer()
# TODO: configuration
app.listen 3000

The important thing is to have a Cakefile that can do the tasks your project needs. 重要的是拥有一个可以完成项目所需任务的Cakefile For an Express project, you might want to add a task that not only continuously recompiles your CoffeeScript, but also restarts the server every time you change a source file. 对于Express项目,您可能希望添加一个任务,不仅可以连续重新编译CoffeeScript,还可以在每次更改源文件时重新启动服务器。 Here's a gist of a Cakefile I'm using on one of my projects (you'll have to add "watch-tree" to your `devDependencies). 这是我在我的一个项目中使用的Cakefile的要点 (你必须在你的`devDependencies中添加"watch-tree" )。

ExpressOnSteroids Express + SCSS + COFFEE SCRIPT ExpressOnSteroids Express + SCSS + COFFEE SCRIPT

clone project and start cake task /path/to/cake dev 克隆项目并启动cake task / path / to / cake dev

刚刚发现github上有一个名为'zappa'的项目可能对你很有帮助http://zappajs.org

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM