Running a custom build step

At deployment, before starting your application, you can perform a custom build step by adding a gcp-build script in your package.json file.

When this script is executed, the dependencies in the dependencies and devDependencies fields of your package.json file are available. After executing your custom build step, App Engine removes and regenerates the node_modules folder by only installing the production dependencies declared in the dependencies field of your package.json file.

Example

A custom build script can be used for pre-processing tasks, such as pre-processing CSS, minifying client side JavaScript, or running tools, such as webpack or gulp.

For example, to compile TypeScript to JavaScript, your package.json file might look like:

{
  "name": "appengine-typescript",
  "description": "An example TypeScript app running on Google App Engine.",
  "version": "0.0.1",
  "private": true,
  "license": "Apache Version 2.0",
  "author": "Google Inc.",
  "engines": {
    "node": ">=8.0.0"
  },
  "scripts": {
    "prepare": "npm run gcp-build",
    "pretest": "npm run gcp-build",
    "test": "repo-tools test app -- index.js",
    "posttest": "npm run lint",
    "lint": "tslint -p .",
    "start": "node ./index.js",
    "gcp-build": "tsc -p .",
    "deploy": "gcloud app deploy"
  },
  "dependencies": {
    "express": "^4.16.3",
    "typescript": "^3.0.1"
  },
  "devDependencies": {
    "@google-cloud/nodejs-repo-tools": "^3.3.0",
    "@types/express": "^4.16.0",
    "tslint": "^5.11.0"
  }
}
¿Te ha resultado útil esta página? Enviar comentarios:

Enviar comentarios sobre...

App Engine standard environment for Node.js docs