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 ); magicString = finalise( this, magicString.trim(), exportMode, options );
const code = magicString.toString(); const code = magicString.toString();
let map = magicString.generateMap({ let map = null;
includeContent: true,
file: options.sourceMapFile || options.dest
// TODO
});
// make sources relative. TODO fix this upstream? if ( options.sourceMap ) {
const dir = dirname( map.file ); map = magicString.generateMap({
map.sources = map.sources.map( source => { includeContent: true,
return source ? relative( dir, source ) : null 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 }; return { code, map };
} }

24
src/rollup.js

@ -21,17 +21,27 @@ export function rollup ( entry, options = {} ) {
globalName: options.globalName, globalName: options.globalName,
// sourcemap options // sourcemap options
sourceMap: options.sourceMap, sourceMap: !!options.sourceMap,
sourceMapFile: options.sourceMapFile, sourceMapFile: options.sourceMapFile,
sourceMapRoot: options.sourceMapRoot // sourceMapRoot: options.sourceMapRoot
}); });
code += `\n//# ${SOURCEMAPPING_URL}=${basename( dest )}.map`; let promises = [ writeFile( dest, code ) ];
return Promise.all([ if ( options.sourceMap ) {
writeFile( dest, code ), let url;
writeFile( dest + '.map', map.toString() )
]); 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 ) { return bundlePromise.then( function ( bundle ) {
var result = bundle.generate({ var result = bundle.generate({
format: profile.format, format: profile.format,
sourceMap: true,
sourceMapFile: 'bundle.js' sourceMapFile: 'bundle.js'
}); });

Loading…
Cancel
Save