svg - SVG 的解析路径
问题描述
我弹出 CRA 进行一些配置。
我遇到的问题是 svg 没有解决相对路径。
我的 webpack 配置中的内容如下:
// Process application JS with Babel.
// The preset includes JSX, Flow, and some ESnext features.
{
test: /\.(js|mjs|jsx)$/,
include: paths.appSrc,
loader: require.resolve('babel-loader'),
options: {
customize: require.resolve(
'babel-preset-react-app/webpack-overrides'
),
plugins: [
[
require.resolve('babel-plugin-named-asset-import'),
{
loaderMap: {
svg: {
ReactComponent: '@svgr/webpack?-prettier,-svgo![path]',
},
},
},
],
],
cacheDirectory: true,
// Save disk space when time isn't as important
cacheCompression: true,
compact: true,
},
},
开发配置很好这个问题适用于生产配置。关于如何解决这个问题的任何想法?
谢谢
解决方案
通过覆盖公共路径修复。在 Webpack 的输出部分,将 publicPath 配置为 '/my-project/' 而不是 ''
推荐阅读
- javascript - bootstrap 4 在表单验证上调用 javascript 函数
- python - 检测图像上的斑点,对检测到的斑点进行 3D 绘图,然后计算 PYTHON
- java - 返回 ArrayList 时,我是否必须返回
和它一起? - javascript - 将自定义 CSS 添加到 Vuetify 组件的问题
- algorithm - 贪心算法是否可能也是动态规划算法?
- unity3d - 为什么场景视图分辨率高但游戏视图分辨率低(以像素为单位)
- python-3.x - 使用熊猫的 groupby 和 for 循环
- angular - angular 5调用函数绑定类将导致函数被无限次调用
- string - 如何删除 awk 中的空格和换行符以进行字符串插入?
- c# - 实体框架性能问题