Allow vite plugins to be run before compilation
See original GitHub issueDescribe the problem
So from what I understand, preprocessors (for svelte kit) are basically vite plugins running before vite-plugin-svelte. They also have an easier access to the content of scripts and style tags, but let’s consider the case where only the markup preprocessor is used.
Now, for the sake of portability, I’m using unplugin to create plugins for vite and other similar frameworks.
Unfortunately, these plugins run after the svelte to js transpilation. This means it is not easy to modify .svelte files, because it’s the resulting js that will be modified.
So, I’d love a way to run these plugins before transpilation.
Describe the proposed solution
Add a beforeKitPlugins options:
// svelte.config.js
/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://github.com/sveltejs/svelte-preprocess
// for more information about preprocessors
preprocess: [
preprocess(),
// MyPlugin.transform // This is doable, but prevents using more vite features.
],
kit: {
adapter: adapter(),
vite: {
plugins: [
// MyPlugin(), // I would like this one to run **before** transpilation
],
}
},
// Best option:
pluginsBeforeKit: [
MyPlugin()
]
};
export default config;
Alternatives considered
Create a preprocesssor. But that defeats the purpose of unplugin.
Importance
nice to have
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Plugin API - Vite
It allows you to inspect the intermediate state of Vite plugins. ... User plugins are resolved before running this hook so injecting other...
Read more >Dependency Pre-Bundling - Vite
Vite caches the pre-bundled dependencies in node_modules/.vite . It determines whether it needs to re-run the pre-bundling step based on a few sources:...
Read more >Building for Production - Vite
When it is time to deploy your app for production, simply run the vite build command. By default, it uses <root>/index.html as the...
Read more >Build Options - Vite
This option allows users to set a different browser target for CSS minification from the one used for JavaScript transpilation. It should only...
Read more >Configuring Vite
When running vite from the command line, Vite will automatically try to resolve a config file named vite.config.js inside project root.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

You are right. As long as the sveltekit plugin itself doesn’t use
enforce, using enforce is fine.I’ll mark this as resolved, with the solution being to
enforce: "pre"It doesn’t matter. For rollup and esbuild, there’s no sense of
enforcesince plugins are ordered the way they are defined. Not having support for them doesn’t mean is should be avoided. You can still use it in rollup by placing your unplugin beforerollup-plugin-svelte.