从我个人的经验来看,这两者的关系并不太好:
const { __ } = wp.i18n;
const { registerBlockType } = wp.blocks;
import { ReactComponent as Logo } from "../bv-logo.svg";
import logoWhiteURL from "../purity-logo.svg";
Destructuring
和
import
给了我描述的错误。
通过如下方式重新创建SVG来修复它:
const logo = el(wp.primitives.SVG,
{width: 20, height: 20, viewBox: \'0 0 64 64\'},
el(\'g\',
{
\'fill-rule\': \'evenodd\',
fill: \'none\',
},
el(\'path\', {
fill: \'#3B414C\',
d: \'M-102-193h600v450h-600z\',
}),
el(\'g\', {
fill: \'#2FC5C0\',
\'fill-rule\': \'nonzero\',
},
el(\'path\', {
d: \'M0 0v63.096h63.096V0H0zm60.588 60.588H2.508V2.508h58.08v58.08z\',
}),
el(\'path\', {
d: \'M24.156 44.748l.924 2.508 3.168-7.524-.132-.396s-5.808-15.048-7.788-20.196l-.264-.66h-6.072l.528 1.452c3.168 8.316 9.636 24.816 9.636 24.816zM36.696 44.748l.924 2.508 3.168-7.524-.132-.396s-5.808-15.048-7.788-20.196l-.264-.66h-6.072l.528 1.452c3.3 8.316 9.636 24.816 9.636 24.816zM47.388 18.48h-6.996l3.564 9.24z\',
}),
),
),
);
updateCategory(\'my-blocks\', {icon: logo});
如果您正在运行JSX编译,也可以尝试这样做:
registerBlockType("podkit/home-slider", {
title: __("Home Slider", "podkit"),
icon:
<svg width="20" height="10" viewBox="0 0 20 10" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M18.75 5.162h-18M15 1.196l3.75 3.966L15 9.13" stroke="#e0004d" stroke-width="1.5" stroke-linejoin="round"/></svg>,
...
});