我有一个environment.ts
文件;
export const environment = { token: '345' };
和一个enviroment.development.ts
文件:
export const environment = { token: '123' };
两者都在公共GitHub回购中.我想部署一个应用程序并将令牌值设置为真正的key值,但在Netlify或Vercel上使用环境变量不起作用,因为我为项目设置了它们.我不想在应用程序的任何部分中写入真正的访问令牌.如何部署应用程序并将假 token 价值更改为真实价值?如果我将实际值设为src/environments/environment.development.ts
,它就会公开,但我必须这样做,因为它是Netlify或Vercel获取代码的地方.
如果我添加:
production: true,
token: '345',
价值观仍然没有改变.
以下是: https://angular.io/guide/build#configure-target-specific-file-replacements
angular.json:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"flightSearch": {
"projectType": "application",
"schematics": {},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:application",
"options": {
"outputPath": "dist/flight-search",
"index": "src/index.html",
"browser": "src/main.ts",
"polyfills": ["zone.js"],
"tsConfig": "tsconfig.app.json",
"assets": ["src/favicon.ico", "src/assets"],
"styles": [
"src/styles.css",
"node_modules/primeng/resources/themes/lara-light-blue/theme.css",
"node_modules/primeng/resources/primeng.min.css"
],
"scripts": [],
"server": "src/main.server.ts",
"prerender": true,
"ssr": {
"entry": "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,
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.development.ts"
}
]
}
},
"defaultConfiguration": "production"
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"buildTarget": "flightSearch:build:production"
},
"development": {
"buildTarget": "flightSearch:build:development"
}
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"buildTarget": "flightSearch:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"polyfills": ["zone.js", "zone.js/testing"],
"tsConfig": "tsconfig.spec.json",
"assets": ["src/favicon.ico", "src/assets"],
"styles": ["src/styles.css"],
"scripts": []
}
}
}
}
},
"cli": {
"analytics": "3921564e-694e-4bc9-aa09-49b8c3772415"
}
}