rspack-contrib / rspack-plugin-preact-refresh

Preact refresh plugin for Rspack
MIT License
6 stars 0 forks source link

feat: Add include and exclude option #2

Closed xymopen closed 2 months ago

xymopen commented 2 months ago

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.

LingyuCoder commented 2 months ago

Can you add some test cases?

xymopen commented 2 months ago

Can you add some test cases?

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

LingyuCoder commented 2 months ago

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 commented 2 months ago

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 commented 2 months ago

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 commented 2 months ago

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

LingyuCoder commented 2 months ago

LGTM, thanks for your contribution