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

feat: Add include and exclude option #2

Merged
merged 4 commits into from
Sep 15, 2024
Merged

feat: Add include and exclude option #2

merged 4 commits into from
Sep 15, 2024

Conversation

xymopen
Copy link
Contributor

@xymopen xymopen commented Aug 27, 2024

This PR aims to add the include and exclude option like the @rspack/plugin-react-refresh.

These options are helpful when works with svgr and mdx, or prevent runtime injection to other packages sharing the same workspace.

@chenjiahan chenjiahan requested a review from LingyuCoder August 27, 2024 10:56
@LingyuCoder
Copy link
Contributor

Can you add some test cases?

@xymopen
Copy link
Contributor Author

xymopen commented Aug 31, 2024

Can you add some test cases?

I don't have much experience on that. Can you provide some examples?

@LingyuCoder
Copy link
Contributor

Can you add some test cases?

I don't have much experience on that. Can you provide some examples?

The include and exclude control the rules that determine which modules have code injected by the loader. So you can require some modules, and exclude some of them. Then try to check the number of occurrences of the injected code which should be equal to the number of modules remain.

@xymopen
Copy link
Contributor Author

xymopen commented Sep 6, 2024

I was trying to fit test from @rspack/plugin-react-refresh, however Jest would complain about timeout and done() not being called. Also the prefresh runtime seems to only be injected during HMR. I was trying to understand @rspack/test-tools but the readme on npm only lead me to rspack website and there is no documentation for the package. Can you give me some help?

@LingyuCoder
Copy link
Contributor

LingyuCoder commented Sep 9, 2024

I was trying to fit test from @rspack/plugin-react-refresh, however Jest would complain about timeout and done() not being called. Also the prefresh runtime seems to only be injected during HMR. I was trying to understand @rspack/test-tools but the readme on npm only lead me to rspack website and there is no documentation for the package. Can you give me some help?

You can see this doc. And the code is here. You can try to add some debug code in next function.

When this function is called, the compiler will build again and then the module content will be changed by this loader. Then hot-update.json and hot-update.js will be generated and loaded by runtime, and then the callbacks registered by module.accept will be called. In this callback you should call the done of jest to end this test case.

@xymopen
Copy link
Contributor Author

xymopen commented Sep 13, 2024

I've add some tests. Ping me if you find something wrong.

main.js Outdated Show resolved Hide resolved
@LingyuCoder
Copy link
Contributor

LGTM, thanks for your contribution

@LingyuCoder LingyuCoder merged commit d4c5c5c into rspack-contrib:main Sep 15, 2024
1 check passed
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

Successfully merging this pull request may close these issues.

2 participants