firebase-functions-interop icon indicating copy to clipboard operation
firebase-functions-interop copied to clipboard

Large package when deploying

Open ghost opened this issue 6 years ago • 2 comments

Firebase creates a 38 MB package when I try to deploy my functions. Usually, my functions have less than 1 mb.

a

Curiously, node_modules has exactly 38 MB, however it is supposed to be automatically ignored (https://stackoverflow.com/a/51182549/6696558).

Is this normal when using this package? Is there any configuration I can do to exclude unwanted parts?

ghost avatar Jul 10 '19 23:07 ghost

The culprit appears to be the .dart_tools and packages directories, which aren't necessary at runtime. Here's what I did to fix it:

  • Removed the build from predeploy in package.json
  • Added the following to firebase.json:
"functions": {
    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" run build",
      "npm --prefix \"$RESOURCE_DIR\" run cleanSymlink"
    ],
    "ignore": ["node_modules", ".dart_tool", "packages"]
  },
  • Added the following to package.json
{
  "scripts": {
    "build": "pub run build_runner build --output=build",
    "cleanSymLink": "rimraf ./build/node/packages",
    ...
  },
  ...
  "devDependencies": {
    "rimraf" : "^3.0.0",
    ...
  }
}

Re-run npm install in the functions directory and it should work. Cut mine down from 36MB for the sample Hello World to 97KB while the function still works.

interrobrian avatar Sep 23 '19 04:09 interrobrian

Good finding! I was able to reduce to 100kb. But I wanted to add one more thing - on this page https://console.cloud.google.com/ you can download the files that have been deployed to firebase: image

That helped me understand what the ignore is actually doing / what still had to be added to the ignore in my case.

StefanLobbenmeier avatar May 04 '20 21:05 StefanLobbenmeier