Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tree-shakable issues when building a library on top of heroicons and vite #1171

Open
PedroAugustoRamalhoDuarte opened this issue May 9, 2024 · 0 comments

Comments

@PedroAugustoRamalhoDuarte

Hello, thanks for this library!!

The problem

I am building a component library on top of heroicons and headlessui, but I am having some problem to make my component library tree-shakable. The components that using heroicons are not tree-shakable.

I am using this tool (agadoo) to check tree-shakable config, but I am not sure if we can trust 100% in it.

I saw in the source code that you guys annotate the with PURE annotations, but when I run agadoo with this component its fails

const React = require("react");
function AdjustmentsHorizontalIcon({
  title,
  titleId,
  ...props
}, svgRef) {
  return /*#__PURE__*/React.createElement("svg", Object.assign({
    xmlns: "http://www.w3.org/2000/svg",
    fill: "none",
    viewBox: "0 0 24 24",
    strokeWidth: 1.5,
    stroke: "currentColor",
    "aria-hidden": "true",
    "data-slot": "icon",
    ref: svgRef,
    "aria-labelledby": titleId
  }, props), title ? /*#__PURE__*/React.createElement("title", {
    id: titleId
  }, title) : null, /*#__PURE__*/React.createElement("path", {
    strokeLinecap: "round",
    strokeLinejoin: "round",
    d: "M10.5 6h9.75M10.5 6a1.5 1.5 0 1 1-3 0m3 0a1.5 1.5 0 1 0-3 0M3.75 6H7.5m3 12h9.75m-9.75 0a1.5 1.5 0 0 1-3 0m3 0a1.5 1.5 0 0 0-3 0m-3.75 0H7.5m9-6h3.75m-3.75 0a1.5 1.5 0 0 1-3 0m3 0a1.5 1.5 0 0 0-3 0m-9.75 0h9.75"
  }));
}
const ForwardRef = React.forwardRef(AdjustmentsHorizontalIcon);
module.exports = ForwardRef;

The fix

The fix, it's only add one more pure annotation in forwardRef function call.

// ....
const ForwardRef = /*#__PURE__*/ React.forwardRef(AdjustmentsHorizontalIcon);
module.exports = ForwardRef;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant