我想为Firebase创建多个云功能,并从一个项目同时部署它们.我还想将每个函数分成一个单独的文件.目前我可以创建多个函数,如果我将它们都放在index.js中,例如:
exports.foo = functions.database.ref('/foo').onWrite(event => {
...
});
exports.bar = functions.database.ref('/bar').onWrite(event => {
...
});
Run Code Online (Sandbox Code Playgroud)
但是我想将foo和bar放在单独的文件中.我试过这个:
/functions
|--index.js (blank)
|--foo.js
|--bar.js
|--package.json
Run Code Online (Sandbox Code Playgroud)
foo.js在哪里
exports.foo = functions.database.ref('/foo').onWrite(event => {
...
});
Run Code Online (Sandbox Code Playgroud)
和bar.js是
exports.bar = functions.database.ref('/bar').onWrite(event => {
...
});
Run Code Online (Sandbox Code Playgroud)
有没有办法在不将所有函数放在index.js中的情况下完成此操作?
使用Atom编辑器,安装了 linter -eslint包后,我有一个 node.mjs 脚本,它使用 ES6 模块的import语句导入各种节点模块。
当我使用节点的--experimental-modules标志运行脚本时,脚本运行良好。但是,在使用 Atom 进行编辑时,linter-eslint 说:
Parsing error: Unexpected token import (Fatal)
Run Code Online (Sandbox Code Playgroud)
这个解析错误不是由我的代码文件顶部的 ecmascript“import”语句引起的。相反,它实际上是由于 eslint 认为“import”是一个保留令牌,只能在import 语句中使用,因此不能被import.meta对象使用(如下面的代码行所示):
const __dirname = path.dirname(new URL(import.meta.url).pathname);
Run Code Online (Sandbox Code Playgroud)
我的 .eslintrc.js 文件有这些解析器选项:
'parserOptions':
{
'ecmaVersion': 2018,
'sourceType': 'module'
}
Run Code Online (Sandbox Code Playgroud)
如何配置 eslint 以忽略此特定错误?
我的项目中有一个模板文件,在运行 eslint 时我面临着各种问题。其中一些是 -
error Parsing error: Unexpected token !
error Parsing error: Unexpected token <
为了克服这个问题,我尝试在没有帮助的情况下使用eslint-plugin-ejs
。我也访问过下面的链接 -
还有更多,但再次没有运气。现在我只想将此文件从 eslint 中排除,但找不到方法。任何帮助将不胜感激。
eslint ×2
javascript ×2
node.js ×2
atom-editor ×1
ejs ×1
es6-modules ×1
eslintignore ×1
eslintrc ×1
firebase ×1