使用ng-packagr构建角度库时,导入SVG文件会出错

问题描述

我正在使用nx monorepo,我的一个库正在将SVG文件导入到JS文件之一中。一切正常,但是当我尝试使用ng-packagr构建我的库时,它给我一个错误-

错误:无法从dist / libs / bpo-ui-base / esm2015 / ui / src / lib / hierarchy / config.js中解析“ ./svgs/default.svg””

config.js

import defaultSVG from './svgs/default.svg'

const styleArray = {
  dagre: [
    {
      selector: 'node',style: {
        'background-image': defaultSVG,'background-image-opacity': 1,'background-fit': 'contain','background-clip': 'none',content: 'data(name)','text-valign': 'center','background-opacity': 0,'text-wrap': 'ellipsis','text-max-width': '50px','font-size': '8px',color: '#6A737A','text-halign': 'center','text-margin-x': '0px','text-margin-y': '22px','text-background-color': '#fff','text-background-opacity': 0,'text-border-style': 'solid','text-border-width': '0.2px','text-border-color': '#000','text-border-opacity': 0,'text-background-padding': '1px'
      }
    }
  ]
}

export {
  styleArray
}

default.svg

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<!-- Created using Krita: http://krita.org -->
<svg xmlns="http://www.w3.org/2000/svg" 
    xmlns:xlink="http://www.w3.org/1999/xlink"
    xmlns:krita="http://krita.org/namespaces/svg/krita"
    xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
    width="126.72pt"
    height="132.48pt"
    viewBox="0 0 126.72 132.48">
<defs/>
<ellipse id="shape0" transform="translate(13.8686300612321,16.3237336435986)" rx="49.4913699387679" ry="48.8419731722839" cx="49.4913699387679" cy="48.8419731722839" fill="none" stroke="#777" stroke-width="18.6696" stroke-linecap="square" stroke-linejoin="bevel"/>
</svg>

文件夹结构

-apps
-libs
  -- lib1
  -- lib2
       -- src
       -- lib
          -- folder1
          -- folder2
              -- svgs
                 -- default.svg
              -- config.js

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)