Open brawaru opened 1 year ago
You could use Vite plugin's configResolved
hook to access the list of plugins, including Vite's internal one, that patch the vite:json
plugin too.
Somehow missed the configResolved
hook (perhaps because I tried config
hook, which does not have built-in plugins) and used configureServer
, but I suppose configResolve
works better. Released a new version of my plugin that makes wrapping work in Vite too, but I still feel this issue is relevant, because having a way to exclude files from transformation without plugin patching is much better.
Description
I have developed a plugin for Rollup that automatically compiles ICU MessageFormat messages stored in JSON files of specific schema into an AST. It makes it possible to not bring a huge parser into runtime, which reduces bundle size and improves performance when interpreting the messages. The plugin is
@braw/rollup-plugin-icu-messages
.Unfortunately, Vite's built-in JSON parsing plugin does not include any options to exclude specific files from parsing, which creates a conflict, since either Vite or
icu-messages
finds the file already parsed and fails to process it. In Rollup this conflict could've been easily solved by passingexclude: ['glob/to/locale-files/*.json']
option. Unfortunately, there is no such option in Vite.Suggested solution
Provide filter options (
include
,exclude
) like in common Rollup plugins to exclude or include certain files for transformation, like this:Alternative
formajs compile
(fromformatjs/cli
). This won't work with non-JSON files and creates an intermediate step, which is annoying to deal with (you will have two sets of locale files). It makes sense to pre-compile locale files during the build, it's easy and would be convenient if it all just worked.buildStart
hook of Rollup to then iterate over all plugins and wrap/remove their transform or load methods. Unfortunately, this hook does not work in Vite! Or at least I don't have a slightest clue how to make it work,enforce
,apply
, nothing have worked for me:plugins
is either undefined or simply empty.Additional context
No response
Validations