我尝试用咖啡脚本和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
答案 0 :(得分:1)
最好将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
启动项目。