Browse Source

fix sourcemap options

contingency-plan
Rich-Harris 10 years ago
parent
commit
9ff9d7a186
  1. 24
      src/Bundle.js
  2. 24
      src/rollup.js
  3. 1
      test/test.js

24
src/Bundle.js

@ -274,17 +274,21 @@ export default class Bundle {
magicString = finalise( this, magicString.trim(), exportMode, options );
const code = magicString.toString();
let map = magicString.generateMap({
includeContent: true,
file: options.sourceMapFile || options.dest
// TODO
});
let map = null;
// make sources relative. TODO fix this upstream?
const dir = dirname( map.file );
map.sources = map.sources.map( source => {
return source ? relative( dir, source ) : null
});
if ( options.sourceMap ) {
map = magicString.generateMap({
includeContent: true,
file: options.sourceMapFile || options.dest
// TODO
});
// make sources relative. TODO fix this upstream?
const dir = dirname( map.file );
map.sources = map.sources.map( source => {
return source ? relative( dir, source ) : null
});
}
return { code, map };
}

24
src/rollup.js

@ -21,17 +21,27 @@ export function rollup ( entry, options = {} ) {
globalName: options.globalName,
// sourcemap options
sourceMap: options.sourceMap,
sourceMap: !!options.sourceMap,
sourceMapFile: options.sourceMapFile,
sourceMapRoot: options.sourceMapRoot
// sourceMapRoot: options.sourceMapRoot
});
code += `\n//# ${SOURCEMAPPING_URL}=${basename( dest )}.map`;
let promises = [ writeFile( dest, code ) ];
return Promise.all([
writeFile( dest, code ),
writeFile( dest + '.map', map.toString() )
]);
if ( options.sourceMap ) {
let url;
if ( options.sourceMap === 'inline' ) {
url = map.toUrl();
} else {
url = `${basename( dest )}.map`;
promises.push( writeFile( dest + '.map', map.toString() ) );
}
code += `\n//# ${SOURCEMAPPING_URL}=${url}`;
}
return Promise.all( promises );
}
};
});

1
test/test.js

@ -179,6 +179,7 @@ describe( 'rollup', function () {
return bundlePromise.then( function ( bundle ) {
var result = bundle.generate({
format: profile.format,
sourceMap: true,
sourceMapFile: 'bundle.js'
});

Loading…
Cancel
Save