gpt4 book ai didi

javascript - 如何使用 coffeescript 和 ES6 创建 sails.js 项目

转载 作者:行者123 更新时间:2023-11-30 00:19:58 26 4
gpt4 key购买 nike

我尝试使用 CoffeeScript 和 ES6 创建 sails.js 项目首先,我使用 sails new 'appName'和npm 安装 CoffeeScript --savenpm 安装 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

最佳答案

最好将 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 启动项目。

关于javascript - 如何使用 coffeescript 和 ES6 创建 sails.js 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33508081/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com