Skip to content

fix: remove references to compiler options no longer available in svelte5 #1010

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .changeset/hungry-pans-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/vite-plugin-svelte': patch
---

removed references to compiler options no longer available in svelte5
10 changes: 3 additions & 7 deletions docs/advanced-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,26 +100,22 @@ add `&sourcemap` to `?(raw|direct)&svelte&type=(script|style|all)` queries to in
```js
const compilerOptions = {
dev: false,
generate: 'dom',
css: false,
hydratable: false,
enableSourcemap: false // or {js: true} or {css:true} if sourcemap query is set
generate: 'client',
css: 'external'
};
```

to get output with different compilerOptions, append them as json like this:

```js
//get ssr output of svelte.compile js as {code, map, dependencies}
import script from 'File.svelte?raw&svelte&type=script&compilerOptions={"generate":"ssr"}';
import script from 'File.svelte?raw&svelte&type=script&compilerOptions={"generate":"server"}';
```

only a subset of compilerOptions is supported

- generate
- dev
- css
- hydratable
- customElement
- immutable
- enableSourcemap
6 changes: 3 additions & 3 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ A [picomatch pattern](https://github.com/micromatch/picomatch), or array of patt
plugins: [
svelte({
dynamicCompileOptions({ filename, compileOptions }) {
// Dynamically set hydration per Svelte file
if (compileWithHydratable(filename) && !compileOptions.hydratable) {
return { hydratable: true };
// Dynamically set runes mode per Svelte file
if (forceRunesMode(filename) && !compileOptions.runes) {
return { runes: true };
}
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { svelte } from '@sveltejs/vite-plugin-svelte';
import { defineConfig } from 'vite';

export default defineConfig({
plugins: [svelte({ prebundleSvelteLibraries: true, compilerOptions: { hydratable: true } })],
plugins: [svelte({ prebundleSvelteLibraries: true })],
optimizeDeps: {
include: ['carbon-components-svelte', 'carbon-icons-svelte']
},
Expand Down
6 changes: 3 additions & 3 deletions packages/vite-plugin-svelte/src/public.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ export interface PluginOptions {
* @example
* ```
* ({ filename, compileOptions }) => {
* // Dynamically set hydration per Svelte file
* if (compileWithHydratable(filename) && !compileOptions.hydratable) {
* return { hydratable: true };
* // Dynamically set runes mode per Svelte file
* if (forceRunesMode(filename) && !compileOptions.runes) {
* return { runes: true };
* }
* }
* ```
Expand Down
12 changes: 2 additions & 10 deletions packages/vite-plugin-svelte/src/utils/id.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@ import { DEFAULT_SVELTE_MODULE_EXT, DEFAULT_SVELTE_MODULE_INFIX } from './consta
const VITE_FS_PREFIX = '/@fs/';
const IS_WINDOWS = process.platform === 'win32';

const SUPPORTED_COMPILER_OPTIONS = [
'generate',
'dev',
'css',
'hydratable',
'customElement',
'immutable',
'enableSourcemap'
];
const SUPPORTED_COMPILER_OPTIONS = ['generate', 'dev', 'css', 'customElement', 'immutable'];
const TYPES_WITH_COMPILER_OPTIONS = ['style', 'script', 'all'];

/**
Expand Down Expand Up @@ -102,7 +94,7 @@ function parseRequestQuery(rawQuery) {
throw new Error(
`Invalid compilerOptions in query ${rawQuery}. CompilerOptions are only supported for raw or direct queries with type in "${TYPES_WITH_COMPILER_OPTIONS.join(
', '
)}" e.g. '?svelte&raw&type=script&compilerOptions={"generate":"ssr","dev":false}`
)}" e.g. '?svelte&raw&type=script&compilerOptions={"generate":"server","dev":false}`
);
}
try {
Expand Down
6 changes: 3 additions & 3 deletions packages/vite-plugin-svelte/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ declare module '@sveltejs/vite-plugin-svelte' {
* @example
* ```
* ({ filename, compileOptions }) => {
* // Dynamically set hydration per Svelte file
* if (compileWithHydratable(filename) && !compileOptions.hydratable) {
* return { hydratable: true };
* // Dynamically set runes mode per Svelte file
* if (forceRunesMode(filename) && !compileOptions.runes) {
* return { runes: true };
* }
* }
* ```
Expand Down