2015-11-03 46 views
2

我尝试与咖啡脚本和ES6 首先创建sails.js项目,我用帆新的“应用程序名称” 和 NPM安装咖啡脚本 - 保存 NPM安装通天--save我怎样才能创造一个sails.js项目与咖啡脚本和ES6

和修改app.js

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

但它的东西错

我看到别人可以通过自动创建它(它可以创造app.coffee升ocal.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

最好使用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来启动项目。