mirror of https://github.com/sveltejs/svelte
support using decoded sourcemaps from SourceMapGenerator (#5732)
Co-authored-by: Conduitry <git@chor.date>pull/5737/head
parent
910348fd0d
commit
3d68ceaf8f
@ -0,0 +1,25 @@
|
||||
import MagicString from 'magic-string';
|
||||
import { SourceMapConsumer, SourceMapGenerator } from 'source-map';
|
||||
|
||||
export default {
|
||||
preprocess: {
|
||||
style: async ({ content, filename }) => {
|
||||
const src = new MagicString(content);
|
||||
const idx = content.indexOf('baritone');
|
||||
src.overwrite(idx, idx+'baritone'.length, 'bar');
|
||||
|
||||
const map = SourceMapGenerator.fromSourceMap(
|
||||
await new SourceMapConsumer(
|
||||
// sourcemap must be encoded for SourceMapConsumer
|
||||
src.generateMap({
|
||||
source: filename,
|
||||
hires: true,
|
||||
includeContent: false
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
return { code: src.toString(), map };
|
||||
}
|
||||
}
|
||||
};
|
@ -0,0 +1,12 @@
|
||||
<h1>Testing Styles</h1>
|
||||
<h2>Testing Styles 2</h2>
|
||||
<script>export const b = 2;</script>
|
||||
<style>
|
||||
h1 {
|
||||
--baritone: red;
|
||||
}
|
||||
|
||||
h2 {
|
||||
--baz: blue;
|
||||
}
|
||||
</style>
|
@ -0,0 +1 @@
|
||||
export { test } from '../preprocessed-styles/test';
|
Loading…
Reference in new issue