加拿大税务局WebPack(react-scripts):配置PUBLIC_URL以外的图片的相对路径
我的反应应用程序的目录结构如下。
src assets dummy.svg scss dummy.scss js dummy.js
以下是 CRA 中生成的标准构建格式。
build static js hashed-js.js css hashed-css.css media hashed-image.svg
我已在我的 scss 中将 svg 指定为 background-image: url("../assets/dummy.svg")
如果指定了 PUBLIC_URL,则生成的 CSS 将具有相对于 PUBLIC_URL 的图像路径,如
<代码>背景图像:url(PUBLIC_URL/static/media/hashed-image.svg)
Is there a way or does react-scripts/webpack provides some configuration to have some other variable injected rather than PUBLIC_URL?
类似背景图像:网址(REACT_SOME_OTHER_VARIABLE/static/media/hashed-image.svg)
I've below directory structure for my react app.
src assets dummy.svg scss dummy.scss js dummy.js
Below is the standard build format generated in CRA.
build static js hashed-js.js css hashed-css.css media hashed-image.svg
I've specified a svg in my scss as background-image: url("../assets/dummy.svg")
If PUBLIC_URL is specified, CSS generated will have image path relative to PUBLIC_URL like
background-image: url(PUBLIC_URL/static/media/hashed-image.svg)
Is there a way or does react-scripts/webpack provides some configuration to have some other variable injected rather than PUBLIC_URL?
Something like background-image: url(REACT_SOME_OTHER_VARIABLE/static/media/hashed-image.svg)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论