|
| 1 | +# Migration Guide |
| 2 | + |
| 3 | +<!-- @import "[TOC]" {cmd="toc" depthFrom=2 depthTo=6 orderedList=false} --> |
| 4 | + |
| 5 | +<!-- code_chunk_output --> |
| 6 | + |
| 7 | +- [Migration Guide](#migration-guide) |
| 8 | +- [From `v3` to `v4`](#from-v3-to-v4) |
| 9 | + - [Prepending content to `scss`](#prepending-content-to-scss) |
| 10 | + - [Executing some function before preprocessing](#executing-some-function-before-preprocessing) |
| 11 | + - [Defining preprocessor properties](#defining-preprocessor-properties) |
| 12 | + - [Type-checking components](#type-checking-components) |
| 13 | + |
| 14 | +<!-- /code_chunk_output --> |
| 15 | + |
| 16 | +## From `v3` to `v4` |
| 17 | + |
| 18 | +### Prepending content to `scss` |
| 19 | + |
| 20 | +In `v3`, it was possible to prepend some content for the `scss` language through the `data` property. |
| 21 | + |
| 22 | +```js |
| 23 | +import sveltePreprocess from 'svelte-preprocess'; |
| 24 | + |
| 25 | +sveltePreprocess({ |
| 26 | + scss: { |
| 27 | + data: '// prepended content', |
| 28 | + }, |
| 29 | +}); |
| 30 | +``` |
| 31 | + |
| 32 | +In `v4`, not only `scss`, but every language preprocessor accepts the new `prependData` property. The `data` property is no longer supported. |
| 33 | + |
| 34 | +```js |
| 35 | +import sveltePreprocess from 'svelte-preprocess'; |
| 36 | + |
| 37 | +sveltePreprocess({ |
| 38 | + scss: { |
| 39 | + prependData: '// prepended content for scss', |
| 40 | + }, |
| 41 | + typescript: { |
| 42 | + prependData: '// prepended content for ts', |
| 43 | + }, |
| 44 | +}); |
| 45 | +``` |
| 46 | + |
| 47 | +### Executing some function before preprocessing |
| 48 | + |
| 49 | +The previously `onBefore` property was removed. Instead, enqueue a custom preprocessor before `svelte-preprocess`. |
| 50 | + |
| 51 | +```js |
| 52 | +// v3 |
| 53 | + |
| 54 | +{ |
| 55 | + preprocess: sveltePreprocess({ |
| 56 | + onBefore({ content, filename }) { |
| 57 | + return content.replace('foo', 'bar'); |
| 58 | + }, |
| 59 | + }); |
| 60 | +} |
| 61 | + |
| 62 | +// v4 |
| 63 | +const myPreprocessor = { |
| 64 | + markup({ content }) { |
| 65 | + return { code: content.replace('foo', 'bar') }; |
| 66 | + }, |
| 67 | +}; |
| 68 | + |
| 69 | +// later in your config |
| 70 | +{ |
| 71 | + preprocess: [myPreprocessor, sveltePreprocess()]; |
| 72 | +} |
| 73 | +``` |
| 74 | + |
| 75 | +### Defining preprocessor properties |
| 76 | + |
| 77 | +The previously `transformers` property was removed. Instead, define your preprocessor options in the root object of `svelte-preprocess` auto-preprocessor. |
| 78 | + |
| 79 | +```diff |
| 80 | +import sveltePreprocess from 'svelte-preprocess'; |
| 81 | + |
| 82 | +sveltePreprocess({ |
| 83 | +- transformers: { |
| 84 | + scss: { ... } |
| 85 | +- } |
| 86 | +}); |
| 87 | +``` |
| 88 | + |
| 89 | +### Type-checking components |
| 90 | + |
| 91 | +> TODO |
0 commit comments