首页 > 解决方案 > 将哈希添加到 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");
    }
  }

在此处输入图像描述

标签: angularwebpackangular5angular-cliangular-cli-v6

解决方案


添加“ng build --prod --output-hashing all”,对生成文件的内容进行hash,并将hash附加到文件名,以方便浏览器缓存破坏


推荐阅读