1

I am using Loopback4 to develop api in Node.

I was using the instruction given to build with watch using nodemon

It worked, but it was getting slow, like about 15 seconds in my case.

I search for other other solution and came up with idea of using Turborepo and the nodemon solution.

I wanted to know if there are better solutions or any issues with it

Gist of the solution

  • run build in watch mode and restart the dev server if js files in dist folder change
  • use Turbo repo to run these build and restart server tasks

Steps

  "scripts": {
   "dev:server:watch": "nodemon server.js"
  }
 // watch src folder
 // ignore dist
 // ext only ts files
 // npm start to start the dev server on any changes to the files
 "nodemonConfig": {
   "verbose": true,
   "watch": [
     "src/"
    ],
    "ignore": [
      "dist/*" 
    ],
    "ext": "ts",
    "exec": "npm start"
 }
  • Install turbo build system
yarn add turbo --dev
  • Update nodemon config to restart server on changes in js files in dist folder after build step
 "nodemonConfig": {
    "verbose": true,
    "watch": [
      "./dist/"
    ],
    "ext": "js",
    "exec": "yarn run start"
  },
  • Add turbo.json
{
    "pipeline": {
        "dev": {
            "dependsOn": ["build:watch", "dev:server:watch"]
        },
        "build:watch": {
            "outputs": [
                ".dist/**"
            ]
        },
        "lint": {
            "outputs": []
        }
    }
}
  • Add dev script in package.json "scripts"
 "dev": "turbo run dev",
  • Run
 yarn run dev

This seems to have reduced the build times to about 3 seconds

Can anyone confirm if this is an acceptable solution, points out any issues

Thanks

Azzy
  • 1,717
  • 2
  • 13
  • 17

0 Answers0