Source-map生成和使用源地圖格式
Source-map 是一個能夠生成和使用源地圖格式的開發(fā)包。
這個開發(fā)包是使用異步模塊定義格式編寫的,工作在下面的環(huán)境中:
-
現(xiàn)代瀏覽器支持 ECMAScript 5
-
內(nèi)置火狐作為 JSM 文件(after the build)
-
需要 NodeJS 0.8.X 或更高版本
使用源地圖(Consuming a source map)
var rawSourceMap = {
version: 3,
file: 'min.js',
names: ['bar', 'baz', 'n'],
sources: ['one.js', 'two.js'],
sourceRoot: 'http://example.com/www/js/',
mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA'};var smc = new SourceMapConsumer(rawSourceMap);console.log(smc.sources);// [ 'http://example.com/www/js/one.js',// 'http://example.com/www/js/two.js' ]console.log(smc.originalPositionFor({
line: 2,
column: 28}));// { source: 'http://example.com/www/js/two.js',// line: 2,// column: 10,// name: 'n' }console.log(smc.generatedPositionFor({
source: 'http://example.com/www/js/two.js',
line: 2,
column: 10}));// { line: 2, column: 28 }smc.eachMapping(function (m) { // ...});
評論
圖片
表情
