【问题标题】:Angular 6 - Refused to apply style from '...' because its MIME type ('text/html') is not a supported stylesheetAngular 6 - 拒绝从“...”应用样式,因为它的 MIME 类型(“text/html”)不是受支持的样式表
【发布时间】:2018-07-23 21:32:35
【问题描述】:

当我在 index.html 中引用以下内容时,尝试升级到 Angular 6 并收到以下错误:

拒绝应用来自 'https://localhost:44394/~/assets/primengcss/themes/omega//theme.css' 的样式,因为它的 MIME 类型 ('text/html') 不是受支持的样式表 MIME 类型,并且启用了严格的 MIME 检查。

【问题讨论】:

    标签: reference styles angular6


    【解决方案1】:

    经过一番挖掘,找到了答案(至少对我有用):

    看起来在 Angular 6 中,我们需要在 angular.json 中包含任何外部 CSS(如 bootstrap、fontawesome、Primeng 等),如下所示:

            "styles": [
              "./node_modules/bootstrap/dist/css/bootstrap.min.css",
              "./node_modules/font-awesome/css/font-awesome.min.css",
              "src/styles.css",
              "./node_modules/primeng/resources/themes/omega/theme.css",
              "./node_modules/primeng/resources/primeng.min.css",
              "./node_modules/primeicons/primeicons.css"
            ],
            "scripts": [
              "./node_modules/jquery/dist/jquery.slim.min.js",
              "./node_modules/popper.js/dist/umd/popper.min.js",
              "./node_modules/bootstrap/dist/js/bootstrap.min.js"
            ]   
    

    【讨论】:

    • 我看到了错误,但它是在运行 ng b --prod 并且 src/styles.scss 变成了 styles.281397b30abd8baeff22.css 之后。后一个文件无法识别。这个解决方案应该处理这种情况吗?
    猜你喜欢
    • 2020-11-10
    • 2021-06-04
    • 2018-12-14
    • 2018-10-24
    • 1970-01-01
    • 1970-01-01
    • 2021-11-29
    • 2018-12-11
    • 2021-07-09
    相关资源
    最近更新 更多