Javascript 如何使用coffee脚本和ES6创建sails.js项目
我尝试使用coffee脚本和ES6创建sails.js项目 首先,我使用sails新的“appName” 及 npm安装咖啡脚本--保存 npm安装babel--保存 并修改app.jsJavascript 如何使用coffee脚本和ES6创建sails.js项目,javascript,node.js,coffeescript,sails.js,ecmascript-6,Javascript,Node.js,Coffeescript,Sails.js,Ecmascript 6,我尝试使用coffee脚本和ES6创建sails.js项目 首先,我使用sails新的“appName” 及 npm安装咖啡脚本--保存 npm安装babel--保存 并修改app.js options = { loose : "all", stage : 1, ignore : null, only : null, extensions: null }; require("sails-hook-babel/node_modules/babel
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
最好将
babel
包作为独立包使用,而不是从sails hook babel
使用。我的集成流程如下所示:
1) 安装babel cli
和babel-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
启动项目