我的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.***/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.
angular/devkit#885 :
当前,文件替换功能仅适用于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.
查看此GitHub线程以了解更多信息
现在受支持(已确认) 在Angular 6.1中
This is now supported (confirmed) in Angular 6.1
更多推荐
Angular:如何为每个配置添加唯一的.htaccess文件?
发布评论