我在Angular中使用Nx.我已经运行了@nx/application - setup-ssr生成器,它为战略科学研究局创建了所有必要的文件.在此之前,它用于添加单独的执行器来为SSR(如serve-ssr)的应用程序提供服务,但没有向project.json添加新的执行器,如下所示:

{
  "name": "public",
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
  "projectType": "application",
  "prefix": "app",
  "sourceRoot": "apps/public/src",
  "tags": [],
  "targets": {
    "build": {
      "executor": "@angular-devkit/build-angular:application",
      "outputs": ["{options.outputPath}"],
      "options": {
        "outputPath": "dist/apps/public",
        "index": "apps/public/src/index.html",
        "browser": "apps/public/src/main.ts",
        "polyfills": ["zone.js"],
        "tsConfig": "apps/public/tsconfig.app.json",
        "assets": [
          {
            "glob": "**/*",
            "input": "assets",
            "output": "assets"
          },
          "apps/public/src/favicon.ico",
          "apps/public/src/assets"
        ],
        "styles": ["apps/public/src/styles.scss"],
        "stylePreprocessorOptions": {
          "includePaths": ["styles", "libs/stylekit/src/lib"]
        },
        "scripts": [],
        "server": "apps/public/src/main.server.ts",
        "prerender": true,
        "ssr": {
          "entry": "apps/public/server.ts"
        }
      },
      "configurations": {
        "production": {
          "budgets": [
            {
              "type": "initial",
              "maximumWarning": "500kb",
              "maximumError": "1mb"
            },
            {
              "type": "anyComponentStyle",
              "maximumWarning": "2kb",
              "maximumError": "4kb"
            }
          ],
          "outputHashing": "all"
        },
        "development": {
          "optimization": false,
          "extractLicenses": false,
          "sourceMap": true,
          "namedChunks": true
        }
      },
      "defaultConfiguration": "production"
    },
    "serve": {
      "executor": "@angular-devkit/build-angular:dev-server",
      "configurations": {
        "production": {
          "buildTarget": "public:build:production"
        },
        "development": {
          "buildTarget": "public:build:development"
        }
      },
      "defaultConfiguration": "development"
    },
    "extract-i18n": {
      "executor": "@angular-devkit/build-angular:extract-i18n",
      "options": {
        "buildTarget": "public:build"
      }
    },
    "lint": {
      "executor": "@nx/eslint:lint",
      "outputs": ["{options.outputFile}"],
      "options": {
        "lintFilePatterns": ["apps/public/**/*.ts", "apps/public/**/*.html"]
      }
    },
    "test": {
      "executor": "@nx/jest:jest",
      "outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
      "options": {
        "jestConfig": "apps/public/jest.config.ts"
      }
    },
    "serve-static": {
      "executor": "@nx/web:file-server",
      "options": {
        "buildTarget": "public:build"
      }
    }
  }
}

这意味着,从v17开始,每当您为应用程序提供服务时,默认情况下都会启用SSR,这很可怕,因为您现在所做的每一项更改,应用程序都需要10秒以上的时间才能重新加载,尽管开发服务器使用的是Vite.

我一直在阅读新的(和旧的)SSR文档,并试图找到提到这一点的Github问题,但它没有提到在服务应用程序的同时禁用或启用SSR,或者允许您使用单独的执行器来服务应用程序.

我对此真的很困惑,因为这感觉像是一大倒退.如何在开发中禁用SSR?

推荐答案

只要"SSR"或"PRPRENDER"符合您的配置,就会启用SSR.

您的解决方案是在development配置中将其设置为false:

        "development": {
          "optimization": false,
          "extractLicenses": false,
          "sourceMap": true,
          "ssr": false, // here
          "prerender": false // and here
        }

Angular相关问答推荐

Angular项目的布线不正常工作

如何在init为FALSE时以Angular 初始化主拇指擦除器-Swiper 11.0.6Angular 17 SSR

NG-BOOTSTRAPP SCROLLESPY没有高度就不能工作?

P-DropDown不会使用react 式表单手动设置Value

如果我只在组件中使用某个主题,是否需要取消订阅该主题?

Angular 15 Ref 错误:初始化前无法访问组件 A

如何在 Angular 中顺序执行回调

如何根据响应变化更改 Angular Carousel 的cellsToShow

包含与 ngFor 相关内容的 HTML 输入

react表单上的自定义验证器用于密码并确认密码匹配将未定义的参数导入 Angular 4

Angular2 路由 VS ui-router-ng2 VS ngrx 路由

如何处理解析器中的错误

Angular 6 - NullInjectorError:单元测试中没有 HttpClient 的提供者

相对于根目录的 SCSS 导入

设置 Angular Material Tooltip 的字体大小

带有 Angular 的 Font Awesome 5

Angular 2 单元测试 - @ViewChild 未定义

Angular2 中的providers提供者是什么意思?

*ngIf 带有多个异步管道变量

Angular单元测试输入值