Is it possible to provide a manual name for the chunk(s) emitted for a code split route? (with Vite)
I'm considering the possibility of conditionally allowing access to certain parts of the bundle via middleware but I would need a way to reliably identify what the chunk contains by its name. Is this currently possible or is it a feature that might be considered?
2 Replies
ratty-blush•3w ago
what exactly do you want do do here?
adverse-sapphire•3w ago
Just chiming in here since I've done exactly this, however perhaps not to the extent you are hoping.
In my company, we have essentially created one large config file that has each route id mapped to whether the route is active or not.
We then pass through the matches from beforeLoad to a middleware function which checks this config and throws a notFound error if the route is disabled.
This should effectively do what I think you are wanting, although it would likely still send the code to the client for that route which may not be desired.
It's worth keeping in mind that no code on the client is actually secure, middleware running in router on the client doesn't do anything other than stop a standard user from accessing things they shouldn't; so youneed to go the full way and ensure that the files cannot be accessed on the server if you truly want to prevent the code being sent to the client