Compiles and packages TypeScript projects for consumption by other build tools, bundlers and dev servers e.g. ts-node, vite, esbuild etc.
- Creates an importable package in
{projectRoot}/dist
- Generates source maps
- Uses
{projectRoot}.swcrc
as base SWC config, if present
- Generates SWC path mappings based on tsconfig
baseUrl
& paths
project.json
{
"targets": {
"build": {
"executor": "nx-simple:build"
}
}
}
package.json
{
"type": "module",
"exports": {
"types": "src/index.ts", // 👈 typescript file entry point – enables intellisense to resolve module
"import": "dist/index.js" // 👈 path to compiled file – enables build tools to resolve module
}
}
tsconfig.json
{
"extends": "../../tsconfig.base.json",
"compilerOptions": { "baseUrl": "src" } // 👈 tells nx-simple where source files are located
}
package.json (root)
// Setting up workspaces ensure that other tools can import your projects.
{
"workspaces": ["packages/**"]
}
nx.json
{
"namedInputs": {
"default": ["{projectRoot}/**/*"]
},
"targetDefaults": {
"nx-simple:build": {
"inputs": ["default"],
"outputs": ["{projectRoot}/dist"]
}
},
"build": {
"dependsOn": ["^build"]
}
}
Param |
Type |
Description |
Default |
targetRuntime |
"es5" | "es6" | "esYYYY" |
the target JavaScript environment |
"es2020" |
The executor also reads configuration from these files:
File |
Param |
Required |
Description |
tsconfig.json |
compilerOptions.baseUrl |
yes |
the directory containing source code (within project directory) |
package.json |
main |
yes |
the location of the compiled entry point |
package.json |
types |
if lib |
the location of the source entry point |
package.json |
exports |
if multiple entry points |
a map of entry points |
.swcrc |
{} |
no |
swc configuration, which may be partially overwritten by the executor |
File |
Param |
Required |
Description |
nx.json |
targetDefaults |
yes |
Inform Nx where the executor writes its artefacts. See nx.json example. |
package.json |
workspaces |
yes |
Allow the package to be imported by its package name, and be resolved by other tools |