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

perf: generate source maps only when explicitly set #478

Merged
merged 1 commit into from Apr 26, 2017
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
13 changes: 10 additions & 3 deletions lib/loader.js
Expand Up @@ -16,10 +16,16 @@ 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") {
map = JSON.stringify(map);
if(sourceMap) {
if (map && typeof map !== "string") {
map = JSON.stringify(map);
}
} else {
// Some loaders (example `"postcss-loader": "1.x.x"`) always generates source map, we should remove it
map = null;
}

processCss(content, map, {
Expand All @@ -28,7 +34,8 @@ module.exports = function(content, map) {
to: loaderUtils.getCurrentRequest(this),
query: query,
minimize: this.minimize,
loaderContext: this
loaderContext: this,
sourceMap: sourceMap
}, function(err, result) {
if(err) return callback(err);

Expand Down
4 changes: 2 additions & 2 deletions lib/processCss.js
Expand Up @@ -200,12 +200,12 @@ module.exports = function processCss(inputSource, inputMap, options, callback) {
// we need a prefix to avoid path rewriting of PostCSS
from: "/css-loader!" + options.from,
to: options.to,
map: {
map: options.sourceMap ? {
prev: inputMap,
sourcesContent: true,
inline: false,
annotation: false
}
} : null
}).then(function(result) {
callback(null, {
source: result.css,
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 @@ -95,4 +113,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; }", ""]
]);
});