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 13a251f
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,13 +16,17 @@ 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 {
map = null;
}

processCss(content, map, {
moduleMode: moduleMode,
mode: moduleMode ? "local" : "global",
from: loaderUtils.getRemainingRequest(this),
to: loaderUtils.getCurrentRequest(this),
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 13a251f

Please sign in to comment.