#Using Nest-CLI plugins in NX

7 messages · Page 1 of 1 (latest)

sudden basin
#

Does anyone know how to enable nest-cli plugins in an nx monorepo?

The base apps generated by NX don't leverage nest-cli.json.

The nx configuration ends up looking something like this (you'll notice my attempt to get the swagger plugin to work).

I feel like this is a failing on the NX side of things, but perhaps there might be some guidance from NestJS folks here that might know of a way to enable this. I'm considering dropping the webpack executor and seeing if I can just run the nest-cli directly, but I might have to duplicate a lot of monorepo configuration for that to work, which isn't ideal.

{
  "name": "ease-backend",
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
  "sourceRoot": "apps/ease-backend/src",
  "projectType": "application",
  "targets": {
    "build": {
      "executor": "@nx/webpack:webpack",
      "outputs": ["{options.outputPath}"],
      "defaultConfiguration": "production",
      "options": {
        "target": "node",
        "compiler": "tsc",
        "outputPath": "dist/apps/ease-backend",
        "main": "apps/ease-backend/src/main.ts",
        "tsConfig": "apps/ease-backend/tsconfig.app.json",
        "assets": ["apps/ease-backend/src/assets"],
        "isolatedConfig": true,
        "webpackConfig": "apps/ease-backend/webpack.config.js",
        "transformers": [
          {
            "name": "@nestjs/swagger/plugin",
            "options": {
              "classValidatorShim": false,
              "introspectComments": true
            }
          }
        ],
        "generatePackageJson": true
      },
      "configurations": {
        "development": {},
        "production": {}
      }
    },
    "serve": {
      "executor": "@nx/js:node",
      "defaultConfiguration": "development",
      "options": {
        "buildTarget": "ease-backend:build"
      },
      "configurations": {
        "development": {
          "buildTarget": "ease-backend:build:development"
        },
        "production": {
          "buildTarget": "ease-backend:build:production"
        }
      }
    },
    "lint": {
      "executor": "@nx/linter:eslint",
      "outputs": ["{options.outputFile}"],
      "options": {
        "lintFilePatterns": ["apps/ease-backend/**/*.ts"]
      }
    },
    "test": {
      "executor": "@nx/jest:jest",
      "outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
      "options": {
        "jestConfig": "apps/ease-backend/jest.config.ts",
        "passWithNoTests": true
      },
      "configurations": {
        "ci": {
          "ci": true,
          "codeCoverage": true
        }
      }
    }
  },
  "tags": ["scope:server"]
}
#

Oops turns my config above is correct

#

Might be a worthwhile addition to the docs, to add the plugin in this fashion:

"targets": {
    "build": {
      ... config values
      "options": {
        "transformers": [
          {
            "name": "@nestjs/swagger/plugin",
            "options": {
              "classValidatorShim": false,
              "introspectComments": true
            }
          }
        ]
      }
    },
sullen radish
#

Nx has this documented, which looks like you've already found. I'm not sure if we'd want to add this to Nest's docs or not, as they're the ones integrating with our utilities, not the other way around, and if they change the API then we have to understand their change and reflect it in our documentation

sudden basin
#

Yeah I understand that for sure

#

The only spot that's a little tricky is that it's unclear how to provide the plugin without resorting to the nest-cli

#

Assuming I'm not using nx at all, would there be a way to pass the plugin to tsc/swc natively?