Skip to content

Instantly share code, notes, and snippets.

@sjinks
Created November 20, 2019 19:19
Show Gist options
  • Save sjinks/681fd641590b7e8922ffd07b31ad6207 to your computer and use it in GitHub Desktop.
Save sjinks/681fd641590b7e8922ffd07b31ad6207 to your computer and use it in GitHub Desktop.
Extracts sources form a sourcemap - quick and dirty
const sourceMap = require('source-map');
const fs = require('fs');
const path = require('path');
const fg = require('fast-glob');
(async function() {
const entries = await fg('*.map');
entries.forEach(async (fname) => {
const consumer = await new sourceMap.SourceMapConsumer(JSON.parse(fs.readFileSync(fname)));
for (const source of consumer.sources) {
const code = consumer.sourceContentFor(source);
const file = source.replace('webpack://', './');
fs.mkdirSync(path.dirname(file), { recursive: true });
fs.writeFileSync(file, code);
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment