Axel Stone
Axel Stone

Reputation: 1580

NX serve certain assets only for development (localhost)

I've added this into project.json under targets.build.options.assets:

{
   "input": "apps/xyz/src/content-providers",
   "glob": "**/*",
   "output": "content-providers"
}

which is served correctly on localhost:4200/content-providers/....

Now I would like to serve those files only when I'm developing the app locally but not in production or when deploying the app to test server. It is possible to achieve that with Nx config?


Here is the whole project.json:

{
  "name": "xyz",
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
  "sourceRoot": "apps/xyz/src",
  "projectType": "application",
  "targets": {
    "build": {
      "executor": "@nx/webpack:webpack",
      "outputs": ["{options.outputPath}"],
      "options": {
        "outputPath": "dist/apps/mam",
        "index": "apps/xyz/src/index.html",
        "main": "apps/xyz/src/main.tsx",
        "polyfills": "apps/xyz/src/polyfills.ts",
        "tsConfig": "apps/xyz/tsconfig.app.json",
        "assets": [
          "apps/xyz/src/icons/favicon.ico",
          "apps/xyz/src/config.js",
          {
            "input": "apps/xyz/src/content-providers",
            "glob": "**/*",
            "output": "content-providers"
          }
        ],
        "styles": [],
        "scripts": [],
        "webpackConfig": "apps/xyz/webpack.config.js",
        "isolatedConfig": true
      },
      "configurations": {
        "production": {
          "fileReplacements": [
            {
              "replace": "apps/xyz/src/environments/environment.ts",
              "with": "apps/xyz/src/environments/environment.prod.ts"
            }
          ],
          "optimization": true,
          "outputHashing": "all",
          "sourceMap": false,
          "extractCss": true,
          "namedChunks": false,
          "extractLicenses": true,
          "vendorChunk": false,
          "budgets": [
            {
              "type": "initial",
              "maximumWarning": "500kb",
              "maximumError": "1mb"
            }
          ]
        },
        "development": {
          "extractLicenses": false,
          "optimization": false,
          "sourceMap": true,
          "vendorChunk": true
        }
      },
      "defaultConfiguration": "production"
    },
    "serve": {
      "executor": "@nx/webpack:dev-server",
      "options": {
        "buildTarget": "xyz:build",
        "hmr": true
      },
      "configurations": {
        "production": {
          "buildTarget": "xyz:build:production",
          "hmr": false
        },
        "development": {
          "buildTarget": "xyz:build:development"
        }
      },
      "defaultConfiguration": "development"
    },
    "lint": {
      "executor": "@nx/eslint:lint",
      "outputs": ["{options.outputFile}"]
    },
  },
  "tags": ["type:app"]
}

Upvotes: 2

Views: 110

Answers (0)

Related Questions