Angular:如何为每个配置添加唯一的.htaccess文件? [英] Angular: how to add a unique .htaccess file per configuration?
问题描述
我的Angular应用程序包含2个构建配置:过渡和生产.
My Angular app contains 2 build configurations: staging, and production.
目前,对于我的所有版本,我都有一个标准的.htaccess
文件,方法是将其包含在我的资产中:
Currently I have a standard .htaccess
file for all builds, by including it in my assets:
"assets": [
"src/.htaccess",
"src/assets",
"src/favicon.png"
],
我想用.htpasswd
文件用密码保护我的登台构建目录,所以我更新了资产以包含它:
I want to password protect my staging build directory with a .htpasswd
file, so I updated my assets to include it:
"assets": [
"src/.htaccess",
"src/.htpasswd"
"src/assets",
"src/favicon.png"
],
htpasswd
文件可以包含在每个版本中,因为在.htaccess
文件中没有提及,它什么都不做.
The htpasswd
file can be included in every build, because without a mention in the .htaccess
file, it does nothing.
然后,我创建了另一个名为.htaccess.dev
的.htaccess
文件,并添加了以下几行:
Then, I've created a second .htaccess
file, called .htaccess.dev
, with the following added lines:
AuthName "Protected"
AuthUserFile /home/admin/domains/dev.***.com/public_html/.htpasswd
AuthGroupFile /dev/null
AuthType Basic
require valid-user
此带有多余行的文件应替换登台构建中的.htaccess
文件,因此我在我的angular.json
文件中添加了以下配置:
This file with the extra lines should replace the .htaccess
file in the staging build, so I added the following configuration to my angular.json
file:
"build": {
...
"configurations": {
"staging": {
...
"fileReplacements": [
{
"replace": "src/.htaccess",
"with": "src/.htaccess.dev"
},
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.staging.ts"
}
]
}
}
}
fileReplacements
适用于我的.env
,但是它不能代替我的htaccess文件.为什么?
fileReplacements
works fine for my .env
, but It does not replace my htaccess file. Why?
推荐答案
啊,看来fileReplacements
仅适用于.ts
文件.
Ah, it seems that fileReplacements
only works for .ts
files.
当前,文件替换功能仅适用于TS文件.更具体地说,它仅适用于webpack编译器主机中的文件.
Currently, the file replacement functionality works only for TS files. More specifically - it works only for files that are part of the webpack compiler host.
(显然)这将在Angular 6.1中修复.
This will (apparently) be fixed in Angular 6.1.
现在受支持(已确认) 在Angular 6.1中
This is now supported (confirmed) in Angular 6.1
这篇关于Angular:如何为每个配置添加唯一的.htaccess文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!