angular - 将环境变量传递给 angular.json 文件。(角7)
问题描述
我正在尝试在 angular.json 文件中使用环境变量。我怀疑这是不可能的,但我想看看是否有人知道。我用它来指向服务器生成的信号器文件(问题是在开发与暂存时它是不同的baseUrl)。所以... angular.json
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"ab-inbev-web2": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist",
"index": "src/index.html",
"main": "src/main.ts",
"tsConfig": "src/tsconfig.json",
"assets": [
"src/assets",
"src/favicon.ico"
],
"scripts": [
"node_modules/bootstrap/dist/js/bootstrap.min.js",
"http://site-dev.com/signalr/hubs"
and when on staging
"http://site-stage.com/signalr/hubs"
]
环境.ts
export const environment = {
baseUrlWithSlash: 'http://site-prod.com/',
logoffWarningTimeoutSeconds: 600,
production: true,
searchDelimiters: /[,;\n]+/
};
environment-local.ts
export const environment = {
baseUrlWithSlash: 'http://site-dev.com/',
logoffWarningTimeoutSeconds: 600,
production: true,
searchDelimiters: /[,;\n]+/
};
等等...
我试图避免对其进行硬编码并尝试在本地运行时让它工作。我想也许有一种方法可以嗅探 angular.json 文件中的位置并执行 if 语句。
解决方案
推荐阅读
- reactjs - 为不同的 Firebase 项目(环境)自定义 React 应用构建
- javascript - 当 url 错误时,为什么 createElement 中没有任何错误
- linux - 当我运行 docker-compose up 命令时,出现此错误。有人可以帮助我吗?
- ruby-on-rails - ransack + AASM:ArgumentError 参数数量错误(给定 1,预期为 0)
- php - 删除 WooCommerce 产品数据中添加的限制选项卡
- ckeditor - CKEditor 5 - img 元素上的 writer.setAttribute('title', ...) 不起作用
- mysql - 使用触发器在 MySQL 中计算列值?
- python - 在现有 PDF 上插入 PDF 页面
- git - 将代码推送到谷歌源代码库错误
- c# - Microsoft Graph - Memberof 字段为空