Cloud API Overview > @adpt/cloud > nodejs > NodeImageBuildOptions > optimizedImage
nodejs.NodeImageBuildOptions.optimizedImage property
Build an image that allows for better layer caching of node_modules
Copies all package.json
, yarn.lock
, package-log.json
, and npm-shrinkwrap.json
files, then installs node_modules, then copies all the source files, and reruns install. This allows the first install of node_modules to be its own cacheable layer that does not need to be rebuilt when the source code changes, only when one of the aforementioned files changes.
There are certain caveats to using this option. First, if baseImage
or nodeVersion runs npm version 7 or later (nodeVersion >= 15), or you are using yarn, any lifecycle scripts you have cannot fail if the full source directory is not present. Neither yarn nor npm have a way to install node_modules, run the lifecycle scripts for dependencies, but skip these scripts for the main package. As a result, the preinstall run will run the lifecycle scripts without the full source present. It appears that npm versions prior to 7 don't run the lifecycle scripts for the main package, so this should not be an issue. Caveat emptor.
Signature:
optimizedImage?: boolean;