This vite-plugin-remove-blocks might be an option. It allows to remove marked blocks from any type of code during the build stage.
The plugin was released recently, so any feedback is welcome.