Skip to content

Commit

Permalink
fix: remove references to compiler options no longer available in sve…
Browse files Browse the repository at this point in the history
…lte5
  • Loading branch information
dominikg committed Oct 28, 2024
1 parent 339e8d3 commit ab12eab
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 27 deletions.
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 immutable flag per Svelte file
if (compileWithImmutable(filename) && !compileOptions.immutable) {
return { immutable: 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 immutable flag per Svelte file
* if (compileWithImmutable(filename) && !compileOptions.immutable) {
* return { immutable: 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 immutable flag per Svelte file
* if (compileWithImmutable(filename) && !compileOptions.immutable) {
* return { immutable: true };
* }
* }
* ```
Expand Down

0 comments on commit ab12eab

Please sign in to comment.