I have written my firebase functions in ES2017 code, which I had to transpile since I cannot deploy functions with ES2017 JavaScript. The way I understand it is firebase serve
serves up the functions to run in my local environment (which uses ES2017) and firebase deploy
deploys the functions to the cloud (no ES2017).
Before I deploy, I npm run prepare
and babel grabs my index.js file in the main folder, transpiles it and puts in in a /dist folder, along with some config files.
In order to get firebase to deploy from the ./dist folder, I set up the entry point "main": "./dist/index.js"
in the package.json. However, this means when I want to firebase serve
for my local environment, I serve up the transpiled functions from the ./dist folder. So I have to keep changing between "main": "index.js"
and "main": "./dist/index.js"
depending on whether I want to serve the functions locally or deploy the transpiled functions.
This is despite having specified where I want to serve and deploy from, like so:
"scripts": {
"lint": "./node_modules/.bin/eslint .",
"serve": "firebase serve --only functions",
"shell": "firebase experimental:functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions/dist",
"logs": "firebase functions:log"
}
My entire package.json file:
{
"main": "./dist/index.js",
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"lint": "./node_modules/.bin/eslint .",
"serve": "firebase serve --only functions",
"shell": "firebase experimental:functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions/dist",
"logs": "firebase functions:log"
},
"dependencies": {
"babel-runtime": "^6.26.0",
"cors": "^2.8.4",
"cross-fetch": "^2.1.0",
"firebase-admin": "^5.8.2",
"firebase-functions": "^1.0.1",
"moment": "^2.22.1"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.6.1",
"eslint": "^4.12.0",
"eslint-plugin-promise": "^3.6.0"
},
"scripts": {
"prepare": "babel ./*.js --retain-lines -d ./dist && cp -a ./private ./dist/private",
"lint": "./node_modules/.bin/eslint --max-warnings=0 ."
},
"private": true
}