You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
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 };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|