Skip to content

Commit

Permalink
Fixed: generate source maps when they are actually requested.
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Apr 11, 2017
1 parent 2ee7552 commit e8d3dc2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/loader.js
Expand Up @@ -16,10 +16,14 @@ module.exports = function(content, map) {
var root = query.root;
var moduleMode = query.modules || query.module;
var camelCaseKeys = query.camelCase || query.camelcase;
var sourceMap = query.sourceMap || false;
var resolve = createResolver(query.alias);

if(map !== null && typeof map !== "string") {
if(sourceMap && map !== null && typeof map !== "string") {
map = JSON.stringify(map);
} else {
// Some loaders (example `postcss-loader: 1`) always generate source map, we should remove their
map = null;
}

processCss(content, map, {
Expand Down
27 changes: 27 additions & 0 deletions test/sourceMapTest.js
Expand Up @@ -10,6 +10,24 @@ describe("source maps", function() {
testWithMap("falsy: undefined map doesn't cause an error", ".class { a: b c d; }", undefined, [
[1, ".class { a: b c d; }", ""]
]);
testWithMap("should don't generate sourceMap when `sourceMap: false` and map exist",
".class { a: b c d; }",
{
file: 'test.css',
mappings: 'AAAA,SAAS,SAAS,EAAE',
names: [],
sourceRoot: '',
sources: [ '/folder/test.css' ],
sourcesContent: [ '.class { a: b c d; }' ],
version: 3
},
[
[1, ".class { a: b c d; }", ""]
],
{
query: "?sourceMap=false"
}
);
testMap("generate sourceMap (1 loader)", ".class { a: b c d; }", undefined, {
loaders: [{request: "/path/css-loader"}],
options: { context: "/" },
Expand Down Expand Up @@ -61,4 +79,13 @@ describe("source maps", function() {
version: 3
}]
]);
testMap("don't generate sourceMap (1 loader)", ".class { a: b c d; }", undefined, {
loaders: [{request: "/path/css-loader"}],
options: { context: "/" },
resource: "/folder/test.css",
request: "/path/css-loader!/folder/test.css",
query: "?sourceMap=false"
}, [
[1, ".class { a: b c d; }", ""]
]);
});

0 comments on commit e8d3dc2

Please sign in to comment.