Skip to content

Commit

Permalink
docs: update documentation for preprocessor sourcemap output (#6438)
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikg committed Jun 24, 2021
1 parent 716d545 commit 2c488f4
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions site/content/docs/04-compile-time.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,24 @@ Each `markup`, `script` or `style` function must return an object (or a Promise

The `markup` function receives the entire component source text, along with the component's `filename` if it was specified in the third argument.

> Preprocessor functions may additionally return a `map` object alongside `code` and `dependencies`, where `map` is a sourcemap representing the transformation. In current versions of Svelte it will be ignored, but future versions of Svelte may take account of preprocessor sourcemaps.
> Preprocessor functions should additionally return a `map` object alongside `code` and `dependencies`, where `map` is a sourcemap representing the transformation.
```js
const svelte = require('svelte/compiler');
const MagicString = require('magic-string');

const { code } = await svelte.preprocess(source, {
markup: ({ content, filename }) => {
const pos = content.indexOf('foo');
if(pos < 0) {
return { code: content }
}
const s = new MagicString(content, { filename })
s.overwrite(pos, pos + 3, 'bar', { storeName: true })
return {
code: content.replace(/foo/g, 'bar')
};
code: s.toString(),
map: s.generateMap()
}
}
}, {
filename: 'App.svelte'
Expand Down

0 comments on commit 2c488f4

Please sign in to comment.