Skip to content

respect sourcemapExcludeSources when constructing map #93

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

Merged
merged 5 commits into from
Oct 20, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ module.exports = function svelte(options = {}) {

const extension = path.extname(id);
if (!~extensions.indexOf(extension)) return null;

const filename = path.relative(process.cwd(), id);

const dependencies = [];
let preprocessPromise;
if (options.preprocess) {
Expand Down Expand Up @@ -313,7 +313,7 @@ module.exports = function svelte(options = {}) {
return compiled.js;
});
},

/**
* If css: true then outputs a single file with all CSS bundled together
*/
Expand All @@ -322,21 +322,20 @@ module.exports = function svelte(options = {}) {
// TODO would be nice if there was a more idiomatic way to do this in Rollup
let result = '';

const mappings = [];
const sourcesContent = [];
const sources = [];
const mappings = [];
const sourcesContent = config.sourcemapExcludeSources ? null : [];

const chunks = Array.from(cssLookup.keys()).sort().map(key => cssLookup.get(key));

for (let chunk of chunks) {
if (!chunk.code) continue;
result += chunk.code + '\n';


if (config.sourcemap && chunk.map) {
const len = sources.length;
config.sourcemapExcludeSources || sources.push(chunk.map.sources[0]);
config.sourcemapExcludeSources || sourcesContent.push(chunk.map.sourcesContent[0]);
sources.push(chunk.map.sources[0]);
if (sourcesContent) sourcesContent.push(chunk.map.sourcesContent[0]);

const decoded = decode(chunk.map.mappings);

Expand Down
9 changes: 5 additions & 4 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ test('can generate a CSS sourcemap – a la Rollup config', async () => {
plugin({
css: value => {
css = value;
css.write('test/sourcemap-test/dist/bundle.css');
css.write('bundle.css');
}
})
],
Expand Down Expand Up @@ -190,7 +190,7 @@ test('respects `sourcemapExcludeSources` Rollup option', async () => {
plugin({
css: value => {
css = value;
css.write('test/sourcemap-test/dist/bundle.css');
css.write('bundle.css');
}
})
],
Expand All @@ -207,8 +207,9 @@ test('respects `sourcemapExcludeSources` Rollup option', async () => {
});

assert.ok(css.map);
assert.is(css.map.sources.length, 0);
assert.is(css.map.sourcesContent.length, 0);
assert.is(css.map.sources.length, 2);
assert.is(css.map.sourcesContent, null);
assert.equal(css.map.sources, ['Bar.html', 'Foo.html']);
});

test('produces readable sourcemap output when `dev` is truthy', async () => {
Expand Down