0

我已经用 ES2017 代码编写了我的 firebase 函数,因为我无法使用 ES2017 JavaScript 部署函数,所以我不得不对其进行转译。我理解它的方式是firebase serve提供在我的本地环境中运行的功能(使用 ES2017)并将firebase deploy这些功能部署到云(没有 ES2017)。

在我部署之前,我npm run prepare和 babel 在主文件夹中获取我的 index.js 文件,将其转换并放入 /dist 文件夹,以及一些配置文件。

为了从 ./dist 文件夹中部署 firebase,我"main": "./dist/index.js"在 package.json 中设置了入口点。但是,这意味着当我想firebase serve为我的本地环境使用时,我会从 ./dist 文件夹中提供转译函数。因此,我必须根据我是要在本地提供功能还是部署转译的功能来不断"main": "index.js"改变"main": "./dist/index.js"

尽管已经指定了我想要服务和部署的位置,如下所示:

  "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"
  }

我的整个 package.json 文件:

{
  "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
}

4

0 回答 0