Angular:如何为每个配置添加唯一的.htaccess文件?

编程入门 行业动态 更新时间:2024-10-25 16:30:03
本文介绍了Angular:如何为每个配置添加唯一的.htaccess文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的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文件?

本文发布于:2023-11-02 08:31:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1551903.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:何为   文件   Angular   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!