Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
7cdc1df
wip: first steps
dominikg Jun 18, 2025
f02a174
wip: second day, getting a hang for it
dominikg Jun 18, 2025
bca41f2
fix: don't destructure api
dominikg Jun 19, 2025
94ac814
mostly working, but hacky raw/direct need work
dominikg Jun 22, 2025
01061c9
ensure hotUpdate returns non-svelte modules, cleanup
dominikg Jun 23, 2025
dc0019c
Merge branch 'main' into refactor/modular-plugins
dominikg Jun 23, 2025
fd8c291
Merge branch 'main' into refactor/modular-plugins
dominikg Jun 23, 2025
04904c2
fix: load raw&svelte files ourselves to prevent vite asset middleware…
dominikg Jun 24, 2025
04531a9
heureka
dominikg Jun 24, 2025
7150c4c
fixes for rolldown: remove duplicate optimizer setup and use svelte5 …
dominikg Jun 24, 2025
210ff7c
fix: add back .svelte optimizer extension, remove unused file
dominikg Jun 24, 2025
40b8dab
chore: remove unused files & code
dominikg Jun 24, 2025
d700ff3
chore: add changesets
dominikg Jun 24, 2025
dfbc8e4
chore: add test for preprocessor transform order
dominikg Jun 25, 2025
a4553e1
chore: fix rolldown-vite
dominikg Jun 25, 2025
e0fe69b
fix again
dominikg Jun 25, 2025
e8089d3
docs: add section about vite-plugin-transforms for preprocessing svelte
dominikg Jun 27, 2025
25ce39c
chore: deprecate plugin.api.sveltePreprocess
dominikg Jun 27, 2025
941db5b
refactor: remove advanced raw queries
dominikg Jun 27, 2025
3ba9fec
Merge branch 'main' into refactor/modular-plugins
dominikg Jun 30, 2025
2e1fd8c
improve inspector plugin
dominikg Jun 30, 2025
afe81cc
chore: improve regex and documentation for code normalization in hotU…
dominikg Jul 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/shiny-hats-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@sveltejs/vite-plugin-svelte-inspector': patch
'@sveltejs/vite-plugin-svelte': patch
---

use vite environment api internally
5 changes: 5 additions & 0 deletions .changeset/thirty-roses-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/vite-plugin-svelte': major
---

split preprocess and compile into separate plugins
8 changes: 2 additions & 6 deletions packages/e2e-tests/autoprefixer-browerslist/src/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import App from './App.svelte';

if (App.toString().startsWith('class ')) {
new App({ target: document.body });
} else {
import('svelte').then(({ mount }) => mount(App, { target: document.body }));
}
import { mount } from 'svelte';
mount(App, { target: document.body });
2 changes: 2 additions & 0 deletions packages/e2e-tests/configfile-custom/svelte.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
console.log('default svelte config loaded');
export default {};
79 changes: 47 additions & 32 deletions packages/vite-plugin-svelte-inspector/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export function svelteInspector(options) {
apply: 'serve',
enforce: 'pre',

applyToEnvironment(env) {
return env.config.consumer === 'client';
},

configResolved(config) {
viteConfig = config;
const environmentOptions = parseEnvironmentOptions(config);
Expand All @@ -43,7 +47,7 @@ export function svelteInspector(options) {
}

// Handle config from svelte.config.js through vite-plugin-svelte
const vps = config.plugins.find((p) => p.name === 'vite-plugin-svelte');
const vps = config.plugins.find((p) => p.name === 'vite-plugin-svelte:config');
const configFileOptions = vps?.api?.options?.inspector;

// vite-plugin-svelte can only pass options through it's `api` instead of `options`.
Expand All @@ -69,42 +73,53 @@ export function svelteInspector(options) {
base: config.base?.replace(/\/$/, '') || ''
};
},

async resolveId(importee, _, options) {
if (options?.ssr || disabled) {
return;
}
if (importee.startsWith('virtual:svelte-inspector-options')) {
return importee;
} else if (importee.startsWith('virtual:svelte-inspector-path:')) {
return importee.replace('virtual:svelte-inspector-path:', inspectorPath);
resolveId: {
filter: {
id: /^virtual:svelte-inspector-/
},
async handler(importee, _, options) {
if (options?.ssr || disabled) {
return;
}
if (importee.startsWith('virtual:svelte-inspector-options')) {
return importee;
} else if (importee.startsWith('virtual:svelte-inspector-path:')) {
return importee.replace('virtual:svelte-inspector-path:', inspectorPath);
}
}
},

async load(id, options) {
if (options?.ssr || disabled) {
return;
}
if (id === 'virtual:svelte-inspector-options') {
return `export default ${JSON.stringify(inspectorOptions ?? {})}`;
} else if (id.startsWith(inspectorPath)) {
// read file ourselves to avoid getting shut out by vites fs.allow check
const file = cleanUrl(id);
if (fs.existsSync(id)) {
return await fs.promises.readFile(file, 'utf-8');
} else {
viteConfig.logger.error(
`[vite-plugin-svelte-inspector] failed to find svelte-inspector: ${id}`
);
load: {
filter: {
id: {
include: [`${inspectorPath}/**`, /^virtual:svelte-inspector-options$/],
exclude: [/style&lang\.css$/]
}
},
async handler(id) {
if (disabled) {
return;
}
if (id === 'virtual:svelte-inspector-options') {
return `export default ${JSON.stringify(inspectorOptions ?? {})}`;
} else if (id.startsWith(inspectorPath)) {
// read file ourselves to avoid getting shut out by vites fs.allow check
const file = cleanUrl(id);
if (fs.existsSync(id)) {
return await fs.promises.readFile(file, 'utf-8');
} else {
viteConfig.logger.error(
`[vite-plugin-svelte-inspector] failed to find svelte-inspector: ${id}`
);
}
}
}
},

transform(code, id, options) {
if (options?.ssr || disabled) {
return;
}
if (id.includes('vite/dist/client/client.mjs')) {
transform: {
filter: { id: /vite\/dist\/client\/client\.mjs(?:\?|$)/ },
handler(code) {
if (disabled) {
return;
}
return { code: `${code}\nimport('virtual:svelte-inspector-path:load-inspector.js')` };
}
}
Expand Down
145 changes: 0 additions & 145 deletions packages/vite-plugin-svelte/src/handle-hot-update.js

This file was deleted.

Loading