Angular Builder 没有更新,我必须更改构建器

问题描述 投票:0回答:1

我对 Angular 的配置很陌生,对构建器不太了解。我正在遵循有关 如何在 Angular 中使用 process.env 的教程,它必须更改 angular.json

 中的一些配置。当我执行 
ng serve
 时出现错误,即 

发生未处理的异常:找不到模块 '@angular-builders/custom-webpack/dist/package.json'

我有两个问题。请看一下我的 angular.json,特别是

projects.architect.serve


"build": { "builder": "@angular-builders/custom-webpack/dist:browser", "options": { "customWebpackConfig": { "path": "src/custom-webpack.config.ts" }, "outputPath": "dist/fitness-proj", "index": "src/index.html", "main": "src/main.ts", "polyfills": [ "zone.js" ], "tsConfig": "tsconfig.app.json", "assets": [ "src/favicon.ico", "src/assets" ], "styles": [ "src/styles.css" ], "scripts": [] }, "configurations": { "production": { "budgets": [ { "type": "initial", "maximumWarning": "500kb", "maximumError": "1mb" }, { "type": "anyComponentStyle", "maximumWarning": "2kb", "maximumError": "4kb" } ], "outputHashing": "all" }, "development": { "buildOptimizer": false, "optimization": false, "vendorChunk": true, "extractLicenses": false, "sourceMap": true, "namedChunks": true } }, "defaultConfiguration": "production" },
    "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "configurations": {
            "production": {
              "browserTarget": "FitnessProj:build:production"
            },
            "development": {
              "browserTarget": "FitnessProj:build:development"
            }
          },
          "defaultConfiguration": "development"
        },

    每当我将“builder”键更改为任何不同的值并运行
  1. ng serve
    ng update
     时,它都会给我上面引用的错误。当我
    ng serve
    时,我还需要做其他事情来更新构建器吗?
  2. 在我上面提供的教程中,以下内容引导我安装具有此文件夹结构的 Angular 构建器:
└── @angular-builders/ └── custom-webpack/ ├── dist/ │ ├── browser/ │ │ └── // a bunch of files │ └── dev-server/ │ └── // a bunch of files ├── node_modules ├── builders.json └── package.json
我想使用自定义 webpack,特别是开发服务器。 

1 阻止我这样做,而且我不知道应该在“构建器”和代码的其他部分中放入什么来使用特定的构建器,以便(最终目标)process.env 工作.

如果有人可以帮助我,那就太好了,我将非常感激。

提前致谢。

angular configuration
1个回答
0
投票
请按照此操作

https://medium.com/@kritipare308/storing-environment-variables-in-angular-adfbc889ef2c

更换线路:

"builder": "@angular-builders/custom-webpack/dist:browser",

"builder": "@angular-builders/custom-webpack:browser",
    
© www.soinside.com 2019 - 2024. All rights reserved.