angular - 如何更改 angular-cli css bundle 生成的资源路径?
问题描述
描述
在我们基于 webpack 的 Angular 项目中,我们使用下一个部署管道:
1. 将所有静态资源生成到静态文件夹
2. 生成索引 html
3. 将静态资源部署到“静态服务器”(S3 存储桶)
4. 将 index.html 部署到“Main服务器”
Dist 文件夹如下所示:
dist
--static
----anivers-bold.eot
----logo.svg
----styles.bundle.css
----code.bundle.js
--index.html
index.html 中的资源链接如下所示:
<script src="http://127.0.0.1:4200/code.bundle.js"></script>
所以,现在我生成了类似的结构和index.html
,但styles.bundle.css
字体和图像设置的链接不正确。
当前:src: url('anivers-bold.eot');
预期:src: url('http://127.0.0.1:4200/anivers-bold.eot');
任何人都知道我如何通过 angular-cli css bundle 更改资源路径?
我尝试什么
您可以在测试存储库中找到测试应用程序。用于ng build
测试构建
我深入研究了 angular-cli,发现了 postcss 插件,它处理资源:node_modules\@angular-devkit\build-angular\src\angular-cli-files\plugins\postcss-cli-resources.js
我尝试使用resourcesOutputPath
参数,但它只生成目录。我也尝试在标签中使用 chane href base
,但在这种情况下,角度路由器会中断。
解决方案
我找到了下一个解决方案:
在 .css 文件中,从远程服务器获取资源,从该服务器请求资源
因此,我们需要使用全局样式的资源(背景 URL、字体)提取样式,所有这些都将正常工作
推荐阅读
- python-3.x - 如何将参数从一个函数传递给其他函数?
- php - PhpMailer 多个附件
- css - 如何从布尔玛模式卡标题中删除关闭按钮?
- linux - 非 RT Linux 内核上的 FIFO/RR 调度程序有多“实时”?
- android - 如何在 AndroidX 中实例化 ViewModel?
- angular - 升级到 Angular 7 后 PrimeNG 树表不呈现
- typescript - Typescript - 更改函数返回类型
- python - Pandas - 将浮点数转换为正确的日期时间或时间对象
- python - pandas datetime 到 unix 时间戳秒
- rust - Cryptopals 在计算密钥大小时挑战 6 个不正确的结果