【发布时间】:2018-10-31 21:19:24
【问题描述】:
背景
- 我有两个 css 文件 - styles.mobile.css 和 styles.desktop.css
- 顾名思义,我为移动和桌面使用了两个单独的 css 观看次数
- 我根据屏幕大小在 index.html 中动态注入 css
- 显然我不能把它们放在styles.css中
- 我已附上文件夹结构截图
问题 有没有办法在我运行 ng build --prod 时向 styles.mobile.css 和 styles.desktop.css 添加散列
检测设备和注入 css 的代码
private addCss(): void {
if (this.currentDevice === "desktop") {
this.document
.getElementById("theme")
.setAttribute("href", "styles.desktop.css");
} else {
this.document
.getElementById("theme")
.setAttribute("href", "styles.mobile.css");
}
}
【问题讨论】:
-
你能发布你的
index.html你是如何检测到它的吗? -
为什么不使用单个css并添加媒体查询以根据屏幕大小区分css?
-
我不明白您为什么不能将它们放入您的
style.css文件中。进行媒体查询,一切顺利。 -
@trichetriche styles.mobile.css 和 styles.desktop.css 完全不同。所以我决定有两个独立的可管理的 css 而不是一个巨大的文件。
-
这并没有改变您可以创建一个文件来导入两个单独文件并使用媒体查询来选择要使用的文件这一事实。
标签: angular webpack angular5 angular-cli angular-cli-v6