gpt4 book ai didi

Angular 6.4.1 环境构建不起作用

转载 作者:行者123 更新时间:2023-12-03 16:20:55 25 4
gpt4 key购买 nike

因此,尝试执行“npm run ng build --configuration=production”并尝试让它使用我的 angular.json 中的 FileReplacements 将 environment.ts 文件替换为 environment.prod.ts
我正在使用以下版本:

"@angular/animations": "^8.0.0-beta.12",
"@angular/cdk": "~7.3.7",
"@angular/common": "^8.0.0-beta.12",
"@angular/compiler": "^8.0.0-beta.12",
"@angular/core": "^8.0.0-beta.12",
"@angular/forms": "^8.0.0-beta.13",
"@angular/material": "^7.3.7",
当我运行上面的命令来设置构建配置时,在 dist 文件夹中,我仍然看到 environment.ts 中引用的 URL,而不是 main-es5.js 文件中的 environment.prod.ts。
src/environments/environment.ts
export const environment = {
production: false,
baseUrl: 'http://0.0.0.0'

};
src/environments/environment.prod.ts
export const environment = {
production: true,
baseUrl: 'http://1.1.1.1'
};
如果有人看到我做错了什么,请告诉我。每次构建时都必须更改 URL 和其他变量。谢谢!
Angular .json
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"NewProject": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"prefix": "app",
"schematics": {},
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/NewProject",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/custom-theme.scss",
"src/styles.css",
"node_modules/ag-grid-community/dist/styles/ag-grid.css",
"node_modules/ag-grid-community/dist/styles/ag-theme-balham.css"
],
"scripts": [],
"es5BrowserSupport": true
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
}
]
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "NewProject:build"
},
"configurations": {
"production": {
"browserTarget": "NewProject:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "NewProject:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.spec.json",
"karmaConfig": "karma.conf.js",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css"
],
"scripts": []
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"tsconfig.app.json",
"tsconfig.spec.json",
"e2e/tsconfig.json"
],
"exclude": [
"**/node_modules/**"
]
}
},
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "NewProject:serve"
},
"configurations": {
"production": {
"devServerTarget": "NewProject:serve:production"
}
}
}
}
}
},
"defaultProject": "NewProject"
}

最佳答案

运行npm run ng build --configuration=production不会将额外的参数传递给 ng build 任务。它只会调用 ng build如果你想构建生产,你可以使用 ng build --configuration=production注意:如果你真的想使用 npm run ...要为生产构建,您需要更改感知参数的方式,如 here 所述并使用 --分开参数发送到任务

npm run ng build -- --configuration=production

关于Angular 6.4.1 环境构建不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62601552/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com