Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate sourcemaps but omit the comment #3120

Merged
merged 5 commits into from
Sep 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/999-big-list-of-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -486,11 +486,11 @@ define(['https://d3js.org/d3.v4.min'], function (d3) {
```

#### output.sourcemap
Type: `boolean | 'inline'`<br>
Type: `boolean | 'inline' | 'hidden'`<br>
CLI: `-m`/`--sourcemap`/`--no-sourcemap`<br>
Default: `false`

If `true`, a separate sourcemap file will be created. If `inline`, the sourcemap will be appended to the resulting `output` file as a data URI.
If `true`, a separate sourcemap file will be created. If `"inline"`, the sourcemap will be appended to the resulting `output` file as a data URI. `"hidden"` works like `true` except that the corresponding sourcemap comments in the bundled files are suppressed.

#### output.sourcemapExcludeSources
Type: `boolean`<br>
Expand Down
4 changes: 3 additions & 1 deletion src/rollup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,9 @@ function writeOutputFile(
url = `${basename(outputFile.fileName)}.map`;
writeSourceMapPromise = writeFile(`${fileName}.map`, outputFile.map.toString());
}
source += `//# ${SOURCEMAPPING_URL}=${url}\n`;
if (outputOptions.sourcemap !== 'hidden') {
source += `//# ${SOURCEMAPPING_URL}=${url}\n`;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/rollup/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ export interface OutputOptions {
outro?: string | (() => string | Promise<string>);
paths?: OptionsPaths;
preferConst?: boolean;
sourcemap?: boolean | 'inline';
sourcemap?: boolean | 'inline' | 'hidden';
sourcemapExcludeSources?: boolean;
sourcemapFile?: string;
sourcemapPathTransform?: (sourcePath: string) => string;
Expand Down
17 changes: 17 additions & 0 deletions test/cli/samples/sourcemap-hidden/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const fs = require('fs');
const assert = require('assert');

module.exports = {
description: 'omits sourcemap comments',
command: 'rollup -i main.js -f es -m hidden -o output.js',
test() {
assert.equal(fs.readFileSync('output.js', 'utf-8').trim(), 'console.log( 42 );');
fs.unlinkSync('output.js');
assert.equal(
fs.readFileSync('output.js.map', 'utf-8').trim(),
'{"version":3,"file":"output.js","sources":["main.js"],"sourcesContent":' +
'["console.log( 42 );\\n"],"names":[],"mappings":"AAAA,OAAO,CAAC,GAAG,EAAE,EAAE,EAAE,CAAC"}'
);
fs.unlinkSync('output.js.map');
}
};
1 change: 1 addition & 0 deletions test/cli/samples/sourcemap-hidden/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log( 42 );
7 changes: 7 additions & 0 deletions test/form/samples/sourcemaps-hidden/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
description: 'correct sourcemaps are written (separate file) without comment',
skipIfWindows: true,
options: {
output: { sourcemap: 'hidden' }
}
};
16 changes: 16 additions & 0 deletions test/form/samples/sourcemaps-hidden/_expected/amd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
define(function () { 'use strict';

function foo () {
console.log( 'hello from foo.js' );
}

function bar () {
console.log( 'hello from bar.js' );
}

console.log( 'hello from main.js' );

foo();
bar();

});
1 change: 1 addition & 0 deletions test/form/samples/sourcemaps-hidden/_expected/amd.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions test/form/samples/sourcemaps-hidden/_expected/cjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

function foo () {
console.log( 'hello from foo.js' );
}

function bar () {
console.log( 'hello from bar.js' );
}

console.log( 'hello from main.js' );

foo();
bar();
1 change: 1 addition & 0 deletions test/form/samples/sourcemaps-hidden/_expected/cjs.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions test/form/samples/sourcemaps-hidden/_expected/es.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function foo () {
console.log( 'hello from foo.js' );
}

function bar () {
console.log( 'hello from bar.js' );
}

console.log( 'hello from main.js' );

foo();
bar();
1 change: 1 addition & 0 deletions test/form/samples/sourcemaps-hidden/_expected/es.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions test/form/samples/sourcemaps-hidden/_expected/iife.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(function () {
'use strict';

function foo () {
console.log( 'hello from foo.js' );
}

function bar () {
console.log( 'hello from bar.js' );
}

console.log( 'hello from main.js' );

foo();
bar();

}());
1 change: 1 addition & 0 deletions test/form/samples/sourcemaps-hidden/_expected/iife.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions test/form/samples/sourcemaps-hidden/_expected/system.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
System.register([], function () {
'use strict';
return {
execute: function () {

function foo () {
console.log( 'hello from foo.js' );
}

function bar () {
console.log( 'hello from bar.js' );
}

console.log( 'hello from main.js' );

foo();
bar();

}
};
});

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions test/form/samples/sourcemaps-hidden/_expected/umd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
(function (factory) {
typeof define === 'function' && define.amd ? define(factory) :
factory();
}(function () { 'use strict';

function foo () {
console.log( 'hello from foo.js' );
}

function bar () {
console.log( 'hello from bar.js' );
}

console.log( 'hello from main.js' );

foo();
bar();

}));
1 change: 1 addition & 0 deletions test/form/samples/sourcemaps-hidden/_expected/umd.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions test/form/samples/sourcemaps-hidden/bar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function bar () {
console.log( 'hello from bar.js' );
}
3 changes: 3 additions & 0 deletions test/form/samples/sourcemaps-hidden/foo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function foo () {
console.log( 'hello from foo.js' );
}
7 changes: 7 additions & 0 deletions test/form/samples/sourcemaps-hidden/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import foo from './foo';
import bar from './bar';

console.log( 'hello from main.js' );

foo();
bar();