Firebase Functionsを使うのにFlowつかいたいけど、コメントスタイルも嫌だったので、Babelした。Flowの設定もはいったままになってます。
要点
firebase deploy
したときfunctionsディレクトリを見にいくのを変えて、カレントディレクトリする。package.jsonをコピーしたくなかったから。
firebase.json
{
"functions": {
"source": "."
}
}
Babel後のファイルはdist/index.js
にするので、その位置を指定するために、"main":dist/index.js
にしてる。
デプロイ用のスクリプトはbabel src --out-dir dist && firebase deploy --only functions
package.json
{
{
"name": "firebase functions babel",
"version": "1.0.0",
"author": "Tomohiko Himura <eiel.hal@gmail.com>",
"license": "MIT",
"main": "dist/index.js",
"scripts": {
"deploy": "babel src --out-dir dist && firebase deploy --only functions"
},
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-preset-env": "^1.6.0",
"babel-preset-flow": "^6.23.0",
"flow-bin": "^0.52.0"
}
}
Cloud Functions runs Node v.6.11.1, so we recommend that you develop locally with this version.
ってかいてあったので、.babelrc
で指定
{
"presets": [
[
"env", {
"targets": { "node": "v6.11.1" }
}
],
"flow"
]
}
サンプルコード。
src/index.js
// @flow
import * as functions from "firebase-functions"
export const https_test = functions.https.onRequest((request, response) => {
response.send('ok');
});