|
9 | 9 | - [Stand-alone processors](#stand-alone-processors)
|
10 | 10 | - [Difference between the auto and stand-alone modes](#difference-between-the-auto-and-stand-alone-modes)
|
11 | 11 | - [Preprocessors](#preprocessors)
|
| 12 | + - [Options](#options) |
12 | 13 | - [Babel](#babel)
|
13 | 14 | - [CoffeeScript](#coffeescript)
|
14 | 15 | - [Less](#less)
|
@@ -247,11 +248,49 @@ export default {
|
247 | 248 |
|
248 | 249 | ## Preprocessors
|
249 | 250 |
|
| 251 | +### Options |
| 252 | + |
250 | 253 | Besides the options of each preprocessors, `svelte-preprocess` also supports these custom options:
|
251 | 254 |
|
252 |
| -| Option | Default | Description | |
253 |
| -| ------------- | ------- | -------------------------------------------------------------------------------------- | |
254 |
| -| `prependData` | `''` | `string` will be prepended to every component part that runs through the preprocessor. | |
| 255 | +| Option | Default | Description | |
| 256 | +| ----------------------------------- | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 257 | +| [`additionalData`](#additionalData) | `undefined` | If a `string`, the value will be prepended to every component part that runs through the preprocessor. If a `function`, it expects to return the content to be preprocessed. | |
| 258 | + |
| 259 | +#### `additionalData` |
| 260 | + |
| 261 | +Type: `string | ({ content: string, filename: string }) => string` |
| 262 | + |
| 263 | +If a `string`, the value will be prepended to every component part that runs through the preprocessor. If a `function`, it expects to return the content to be preprocessed. |
| 264 | + |
| 265 | +```js |
| 266 | +import svelte from 'rollup-plugin-svelte'; |
| 267 | + |
| 268 | +import autoPreprocess from 'svelte-preprocess'; |
| 269 | + |
| 270 | +export default { |
| 271 | + plugins: [ |
| 272 | + svelte({ |
| 273 | + preprocess: autoPreprocess({ |
| 274 | + typescript: { |
| 275 | + additionalData: '// prepended content', |
| 276 | + }, |
| 277 | + scss: { |
| 278 | + // Passing a function |
| 279 | + additionalData({ content, filename }) { |
| 280 | + return [ |
| 281 | + // prepended |
| 282 | + `// I'm at the top of the file`, |
| 283 | + content, |
| 284 | + // appended |
| 285 | + `// And I'm at the bottom!`, |
| 286 | + ].join('\n'); |
| 287 | + }, |
| 288 | + }, |
| 289 | + }), |
| 290 | + }), |
| 291 | + ], |
| 292 | +}; |
| 293 | +``` |
255 | 294 |
|
256 | 295 | ### Babel
|
257 | 296 |
|
|
0 commit comments