Extending
A task can be used as a base template and extended. This is intended to reduce duplicate task definitions.
Extending tasks avoids a lot of duplicated task definitions in bigger projects and monorepos. With the extend property, a task uses another task's configuration as a template.
The following sections and examples use the two predefined tasks in the build.tsc.yaml file — one of the ready-made templates shipped under
best-practices/. Copy it into your project (or include it directly) to follow along.
tasks:
install:
src:
- package.json
- package-lock.json
generates:
- node_modules
cmds:
- npm ci
build:
deps: [ install ]
src:
- tsconfig.json
- src
cmds:
- node_modules/.bin/tsc
generates:
- distExtend a task
Extending tsc:build uses all of its properties as a base. If nothing else is defined, the result is an exact copy that runs in the working directory of the current build file.
tasks:
build:
extend: tsc:build
includes:
tsc: ./build.tsc.yamlOverride properties in an extend
An extending task can override any property, whether the base defines it or not. In this example the dependencies are cleared, so the task runs without depending on install.
tasks:
build:
extend: tsc:build
deps: []
includes:
tsc: ./build.tsc.yamlNaming the base task
extend uses the same <prefix>:<task> addressing as dependencies:
the part before the colon is the include (or
reference) prefix, and the part after it is the task
name in that file. extend: tsc:build means "the build task from the file
included as tsc". To extend a task in the same file, use its bare name
(extend: build-base).