By default, the node.js runtime will execute npm run build if a build script is detected in package.json file. If you require additional control over your build steps before starting your application, you can provide a custom build step. Custom build steps can be executed by adding gcp-build in your package.json file.
To prevent your build from running the npm run build script, you must either:
- Add a
gcp-buildscript with an empty value in yourpackage.jsonfile:"gcp-build":"". For details about configuring thepackage.json, see Node.js buildpacks configurations. Add the
GOOGLE_NODE_RUN_SCRIPTSbuild environment variable with an empty value in yourapp.yamlfile.build_env_variables: GOOGLE_NODE_RUN_SCRIPTS: ''
build_env_variables section in the app.yaml 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.
For more information on how to configure the runtime for custom build steps, see Executing custom build steps during deployment for Node.js buildpacks.
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 the following. Note the gcp-build script:
Serving static files
When you generate or copy files during the custom build step, App Engine does not serve these static files directly from your app using either the static_dir or static_files elements defined in the app.yaml file. Instead, App Engine uploads the static files to the serving infrastructure in the standard environment before running the custom build step. Any request to the files generated or copied during the custom build step results in a 404 NOT FOUND HTTP error.