如何使用咖啡脚本和ES6创建sails.js项目

时间:2015-11-03 20:05:54

标签: javascript node.js coffeescript sails.js ecmascript-6

我尝试用咖啡脚本和ES6创建sails.js项目 首先,我使用sails new'appName' 和 npm install coffee-script --save npm install babel --save

并修改app.js

options = {
  loose     : "all",
  stage     : 1,
  ignore    : null,
  only      : null,
  extensions: null
};
require("sails-hook-babel/node_modules/babel/register")(options);

但这是错误的

我看到其他人可以通过自动创建它(它可以创建app.coffee local.coffee ......等不需要修改) 怎么做?

-----------------------------------------------
error: ** Grunt :: An error occurred. **
error:
------------------------------------------------------------------------
Warning: Task "watch" not found.

Aborted due to warnings.

------------------------------------------------------------------------

error: Looks like a Grunt error occurred--
error: Please fix it, then **restart Sails** to continue running tasks (e.g. watching for changes in assets)
error: Or if you're stuck, check out the troubleshooting tips below.

error: Troubleshooting tips:
error:
error:  *-> Are "grunt" and related grunt task modules installed locally?  Run `npm install` if you're not sure.
error:
error:  *-> You might have a malformed LESS, SASS, CoffeeScript file, etc.
error:
error:  *-> Or maybe you don't have permissions to access the `.tmp` directory?
error:      e.g., `/Users/yangjunzhang/Documents/workspace/burstWork/.tmp` ?
error:
error:      If you think this might be the case, try running:
error:      sudo chown -R 501 /Users/yangjunzhang/Documents/workspace/burstWork/.tmp

1 个答案:

答案 0 :(得分:1)

最好将babel包用作独立包,但不能使用sails-hook-babel。我的整合流程如下所示:

1)安装babel-clibabel-preset-es2015

npm install --save babel-cli babel-preset-es2015

2)使用以下脚本更改您的package.json文件scripts部分:

"scripts": {
  "start": "babel-node --presets es2015 app.js"
}

3)使用npm start脚本启动您的应用程序:

npm start

之后,您可以使用ES6语法编写所有代码,并使用npm start启动项目。