-
Notifications
You must be signed in to change notification settings - Fork 21
Sourcemaps
Rich Harris edited this page Jan 22, 2015
·
2 revisions
Esperanto can create sourcemaps as it converts and bundles your modules, for easier debugging. If you pass sourceMap: true
when creating a module/bundle, the returned value will have a map
property in addition to the code
property.
The value of map
is a version 3 sourcemap, with an additional (non-enumerable) toString()
method which is the equivalent of calling JSON.stringify(map)
.
If you pass sourceMap: 'inline'
, the sourcemap will instead be appended to code
as a data URI.
The following examples demonstrate the pattern:
var source = fs.readFileSync( 'source.js', 'utf-8' );
var cjs = esperanto.toCjs( source, {
sourceMap: true,
sourceMapSource: 'source.js'
sourceMapFile: 'dest.js.map'
});
fs.writeFileSync( 'dest.js', cjs.code );
fs.writeFileSync( 'dest.js.map', cjs.map.toString() );
var source = fs.readFileSync( 'source.js', 'utf-8' );
var cjs = esperanto.toCjs( source, {
sourceMap: 'inline',
sourceMapSource: 'source.js'
sourceMapFile: 'dest.js.map'
});
fs.writeFileSync( 'dest.js', cjs.code );
esperanto.bundle({
base: 'src',
entry: 'main.js'
}).then( function ( bundle ) {
var cjs = bundle.toCjs({
sourceMap: true,
sourceMapFile: 'bundle.js.map'
// note: `sourceMapSource` is unnecessary here
});
fs.writeFileSync( 'bundle.js', cjs.code );
fs.writeFileSync( 'bundle.js.map', cjs.map.toString() );
});
esperanto.bundle({
base: 'src',
entry: 'main.js'
}).then( function ( bundle ) {
var cjs = bundle.toCjs({
sourceMap:'inline',
sourceMapFile: 'bundle.js.map'
});
fs.writeFileSync( 'bundle.js', cjs.code );
});