Skip to content

Commit

Permalink
Fix sourceMappingURL for bundles with multiple entry points
Browse files Browse the repository at this point in the history
  • Loading branch information
lustoykov committed Feb 14, 2019
1 parent a2e38f9 commit c0eff27
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 1 deletion.
@@ -0,0 +1 @@
console.log('hello1');
@@ -0,0 +1 @@
console.log('hello2');
@@ -0,0 +1,6 @@
<html>
<head>
<script src='./a/index.js'> </script>
<script src='./b/index.js'> </script>
</head>
</html>>
@@ -0,0 +1 @@
console.log('hello');
30 changes: 30 additions & 0 deletions packages/core/integration-tests/test/sourcemaps.js
Expand Up @@ -314,4 +314,34 @@ describe('sourcemaps', function() {
);
mapValidator(jsOutput, map);
});

it('should create correct sourceMappingURL', async function() {
const b = await bundle(
path.join(__dirname, '/integration/sourcemap-sourcemappingurl/index.js')
);

const jsOutput = await fs.readFile(b.name, 'utf8');
assert(jsOutput.includes('//# sourceMappingURL=/index.js.map'));
});

it('should create correct sourceMappingURL with multiple entrypoints', async function() {
const b = await bundle([
path.join(
__dirname,
'/integration/sourcemap-sourcemappingurl-multiple-entrypoints/a/index.js'
),
path.join(
__dirname,
'/integration/sourcemap-sourcemappingurl-multiple-entrypoints/b/index.js'
)
]);

const bundle1 = [...b.childBundles][0];
const bundle2 = [...b.childBundles][1];
const jsOutput1 = await fs.readFile(bundle1.name, 'utf8');
const jsOutput2 = await fs.readFile(bundle2.name, 'utf8');

assert(jsOutput1.includes('//# sourceMappingURL=/a/index.js.map'));
assert(jsOutput2.includes('//# sourceMappingURL=/b/index.js.map'));
});
});
2 changes: 1 addition & 1 deletion packages/core/parcel-bundler/src/packagers/JSPackager.js
Expand Up @@ -239,7 +239,7 @@ class JSPackager extends Packager {
if (mapBundle) {
let mapUrl = urlJoin(
this.options.publicURL,
path.basename(mapBundle.name)
path.relative(this.options.outDir, mapBundle.name)
);
await this.write(`\n//# sourceMappingURL=${mapUrl}`);
}
Expand Down

0 comments on commit c0eff27

Please sign in to comment.