css - 使用 webpack 时 CSS 文件路径呈现为 [Object object]
问题描述
在我的fonts.scss
源文件中(如果这是纯 CSS 导入,结果相同)
@font-face {
font-family: "SocialIcons";
src: url("../fonts/social-icons.woff") format("woff");
font-weight: normal;
font-style: normal;
font-display: block;
}
之后npm run build
运行 webpack,它被渲染为:
@font-face {
font-family: "SocialIcons";
src: url([object Object]) format("woff");
font-weight: normal;
font-style: normal;
font-display: block;
}
所以文件路径被破坏,呈现为[object Object]
而不是文件的路径。
这是 WordPress 的 Roots Sage 9.0.10 主题,使用webpack
. 以下是一些关键依赖项:
"css-loader": "^0.28.11",
"file-loader": "^6.2.0",
"node-sass": "^5.0.0",
"postcss-loader": "^4.0.4",
"postcss-safe-parser": "^5.0.2",
"resolve-url-loader": "^3.1.2",
"sass-loader": "~6.0",
"style-loader": "^0.23.1",
"url-loader": "^4.1.1",
"webpack": "~3.10.0",
这个问题似乎仅限于相对路径。当我输入绝对路径时,很好 - 即。url(/wp-content/theme/resources/assets/fonts/social-icons.woff)
但这不适合生产,因为我希望所有引用都指向dist
目录。
有没有人遇到过这种情况,如果有,有解决办法吗?
解决方案
推荐阅读
- video - 如何在 MP4 上叠加透明视频(mp4)?
- angular - 基于角度材料复选框的下一节可见性控制问题
- c# - 在每个线程中获取下一个值的正确方法是什么?
- google-cloud-platform - Google Cloud Dataflow 管道执行在刷新访问令牌期间挂起
- grails - 如何使用拦截器在不使用带有 grails 3 的 Spring Security 的情况下创建登录功能
- html - 将 HTML 标记中的文本提取为单个字符串
- jdbc - 是否可以使用 clickhouse-jdbc 驱动程序对 clickhouse 进行批量更新?
- mysql - 与特定行上mysql中其他列的列更新
- powershell - 如何设置 powershell 脚本以将 GPO 名称视为变量
- jinja2 - 渲染 SLS:此处不允许映射值