Refactor the plugin to use unplugin and add Webpack/Rspack compatibility #198
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've refactored the plugin to use Unplugin so it can be interoperable with other compilers and added support for Webpack/Rspack.
import.meta.webpackContextis used in webpack/rspack environments and parsed to expected module shape.I've also added an example for rspack.
There are some issues during bundling caused by the fact that the examples and packages are using registry version of the package instead of the workspace version. However if you change it to
workspace:*anddtsfile definitions intsup.config.jsto point to../instead ofnode_modules(for some reason on devdistfolders are not linked) it builds (but not type checks ) and you are able to run the example. I did not want to make these changes in the PR, since it is out of scope.I've tested the refactor by utilising the mentioned modifications to package.json and tsup config. Both vite and webpack/rspack works as far as I can tell.
Also the change could be fully backwards compatible by swapping the
defaultexport tounplugin.vite.