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

Usage question: where should the plugin be put in the configuration? #5

Open
SukkaW opened this issue Apr 23, 2023 · 5 comments
Open

Comments

@SukkaW
Copy link
Contributor

SukkaW commented Apr 23, 2023

In my forgetti-loader's README, I mention that forgetti-loader should be put in a way that forgetti is executed before JSX transformation. But I am wondering if it is correct or not.

@lxsmnsyc
Copy link
Owner

It honestly can be put in either way, but I would recommend it putting before the JSX transform happens.

@SukkaW
Copy link
Contributor Author

SukkaW commented Apr 23, 2023

It honestly can be put in either way, but I would recommend it putting before the JSX transform happens.

There is a babel plugin @babel/plugin-transform-react-constant-elements that performs caching jsx call:

// In
const Hr = () => {
  return <hr className="hr" />;
};

const WithChildren = (props) => {
  return <div className={props.className}>
    <hr />
  </div>;
}

// out
var _hr, _hr2;

const Hr = () => {
  return _hr || (_hr = <hr className="hr" />);
};

const WithChildren = (props) => {
  return <div className={props.className}>
    {_hr2 || (_hr2 = <hr />)}
  </div>;
}

I am wondering if by putting the forgetti after the JSX transform, is it possible to achieve the same result (caching _jsx calls).

@lxsmnsyc
Copy link
Owner

It can cache either JSX itself or the transforms, which is why it doesn't matter.

@SukkaW
Copy link
Contributor Author

SukkaW commented Apr 23, 2023

It can cache either JSX itself or the transforms, which is why it doesn't matter.

Thanks!

... but I would recommend it putting before the JSX transform happens.

So is there any reason for that?

@lxsmnsyc
Copy link
Owner

lxsmnsyc commented Apr 23, 2023

So is there any reason for that?

because some frameworks handles the JSX transform itself that it isn't really the same as the normal JSX. Million is a good example. Forgetti must know not to touch the JSX unless the preset says so. A post-transform JSX from Forgetti might also be illegal for the framework using it.

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

2 participants