forked from sveltejs/svelte
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support using decoded sourcemaps from SourceMapGenerator (sveltejs#5732)
Co-authored-by: Conduitry <[email protected]>
- Loading branch information
1 parent
f433d0c
commit f9e1f3c
Showing
4 changed files
with
118 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }; | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { test } from '../preprocessed-styles/test'; |