Created
November 20, 2019 19:19
-
-
Save sjinks/681fd641590b7e8922ffd07b31ad6207 to your computer and use it in GitHub Desktop.
Extracts sources form a sourcemap - quick and dirty
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
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