Page Contents


This module contains a set of common scripts and default configurations to build LoopBack 4 or other TypeScript modules, including:

  • lb-tsc: Use tsc to compile typescript files
  • lb-eslint: Run eslint
  • lb-tslint: Run tslint
  • lb-prettier: Run prettier
  • lb-mocha: Run mocha to execute test cases
  • lb-nyc: Run nyc

These scripts first try to locate the CLI from target project dependencies and fall back to bundled ones in @loopback/build.

Basic use

To use @loopback/build for your package:

  1. Run the following command to add @loopback/build as a dev dependency.

npm i @loopback/build --save-dev

  1. Configure your project package.json as follows:
"scripts": {
    "build": "lb-tsc",
    "build:watch": "lb-tsc --watch",
    "clean": "lb-clean",
    "lint": "npm run prettier:check && npm run eslint",
    "lint:fix": "npm run prettier:fix && npm run eslint:fix",
    "prettier:cli": "lb-prettier \"**/*.ts\" \"**/*.js\"",
    "prettier:check": "npm run prettier:cli -- -l",
    "prettier:fix": "npm run prettier:cli -- --write",
    "eslint": "lb-eslint --report-unused-disable-directives .",
    "eslint:fix": "npm run eslint -- --fix",
    "pretest": "npm run clean && npm run build",
    "test": "lb-mocha \"dist/__tests__\"",
    "posttest": "npm run lint",
    "start": "npm run build && node .",
    "prepublishOnly": "npm run test"

Please remember to replace your-module-name with the name of your module.

Now you run the scripts, such as:

  • npm run build - Compile TypeScript files and copy resources (non .ts files) to outDir
  • npm test - Run all mocha tests
  • npm run lint - Run eslint and prettier on source files
  1. Override default configurations in your project
  • lb-tsc

    By default, lb-tsc searches your project’s root directory for then tsconfig.json. If neither of them exists, a tsconfig.json will be created to extend from @loopback/build/config/tsconfig.common.json.

    To customize the configuration:

    • Create or tsconfig.json in your project’s root directory

        "$schema": "",
        "extends": "@loopback/build/config/tsconfig.common.json",
        "compilerOptions": {
          "outDir": "dist",
          "rootDir": "src"
        "include": ["src"]
    • Set options explicity for the script

      lb-tsc -p tsconfig.json --target es2017 --outDir dist

      For more information, see

    • The following un-official compiler options are available:

      Option Description
      --copy-resources Copy all non-typescript files from src and test to outDir, preserving their relative paths.
  1. Run builds
npm run build



run npm test from the root folder.


See all contributors.