Is it possible to separate build files with nx build node?

1.6k Views Asked by At

I have a node js project with nx workspace and my problem is that my routes for download and upload is with path for example const filePath = path.join(__dirname, '../../templates', fileName). When I run

nx run build

nx combines all files into one single main.js file and thats ruin my paths and my app no longer finds template because its only one folder up not 2. What should I do to tell nx build to build my app like normal and not combining all my files into single file?

1

There are 1 best solutions below

0
On BEST ANSWER

I have made a custom script:

   "start": {
      "executor": "@nrwl/workspace:run-commands",
      "options": {
        "commands": [
          "nodemon -e ts,graphql --exec \"nx run server-authentication:start-nodemon\""
        ],
        "cwd": "apps/server/authentication",
        "parallel": false
      }
    },
    "start-nodemon": {
      "executor": "@nrwl/workspace:run-commands",
      "options": {
        "commands": [
          "nx run server-authentication:ts-build",
          "node ../../../../dist/apps/server/authentication/src/index.js"
        ],
        "cwd": "apps/server/authentication",
        "parallel": false
      }
    },
    "ts-build": {
      "executor": "@nrwl/workspace:run-commands",
      "options": {
        "commands": [
          "tsc -p tsconfig.app.json",
          "tsc-alias -p tsconfig.app.json",
          "ncp src/schema ../../../../dist/apps/server/authentication/src/schema",
          "ncp .env ../../../../dist/apps/server/authentication/src/.env"
        ],
        "cwd": "apps/server/authentication",
        "parallel": false
      }
    },