css - 在 index.html 的顶部添加了捆绑的 css
问题描述
在构建我的 Angular 9.0.4 应用程序的 prod 版本时,css 被捆绑并添加到 dist/index.html 的顶部,如下所示:
<link rel="stylesheet" href="styles.6ea28d52542acb20a4c6.css"><!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>MyTitle</title>
<base href="/">
我认为这导致了 Chrome 中的警告:
Resource interpreted as Stylesheet but transferred with MIME type text/html:
并且样式表未正确呈现。请注意,仅在加载带有子文件夹的域时才会发生这种情况,例如www.mydomain.com/product/1
是否可以配置构建,以便在下面添加样式表元素<base href="/">
,这可能会修复警告?
解决方案
我不知道有任何方法可以移动 css 文件导入,但您可以通过关闭 css 提取来停止此错误:
纱线构建--extractCss=false
或者在 angular.json 中的构建配置中
{
...
"build": {
"configurations": {
"yourBuildName": {
...
"extractCss": false
}
}
}
}
推荐阅读
- javascript - Gremlin Javascript 折叠、合并和展开
- javascript - 带有 HTML 文件的 Node.js 子进程
- java - 这段代码中“this”的实例是什么意思?
- java - 与等效的日历代码相比,生成的 java.time 代码是否具有更多代码语句
- xslt-2.0 - 如何从 x:expect 结果中删除 test:ws 元素在 XSpec
- java - 为什么在使用三元 if/else 运算符时增量运算符 (++/--) 不起作用?
- php - 通过 Web 套接字服务器与特定用户 [Android 设备] 连接
- javascript - 使用 ajax 将点击计数发送到 django 视图
- java - Firebase 实时数据库:有没有办法避免在删除值时调用 onDataChange?
- sap - 如何使用 SAP Fiori Client Android App 访问 SAP Fiori Launchpad?引发 SSL 错误