Merge pull request #10263 from meteor/fix-issue-10112-by-ignoring-inline-source-maps

Ignore inline source maps when minifying CSS files.
This commit is contained in:
Ben Newman
2018-10-10 17:04:36 -04:00
committed by GitHub
2 changed files with 10 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
Package.describe({
name: 'standard-minifier-css',
version: '1.5.0',
version: '1.5.1',
summary: 'Standard css minifier used with Meteor apps by default.',
documentation: 'README.md'
});

View File

@@ -51,6 +51,11 @@ var hashFiles = Profile("hashFiles", function (files) {
return hash.digest("hex");
});
function disableSourceMappingURLs(css) {
return css.replace(/# sourceMappingURL=/g,
"# sourceMappingURL_DISABLED=");
}
// Lints CSS files and merges them into one file, fixing up source maps and
// pulling any @import directives up to the top since the CSS spec does not
// allow them to appear in the middle of a file.
@@ -69,7 +74,8 @@ var mergeCss = Profile("mergeCss", function (css) {
originals[filename] = file;
try {
var parseOptions = { source: filename, position: true };
var ast = CssTools.parseCss(file.getContentsAsString(), parseOptions);
var css = disableSourceMappingURLs(file.getContentsAsString());
var ast = CssTools.parseCss(css, parseOptions);
ast.filename = filename;
} catch (e) {
if (e.reason) {
@@ -114,7 +120,8 @@ var mergeCss = Profile("mergeCss", function (css) {
// Add the contents of the input files to the source map of the new file
stringifiedCss.map.sourcesContent =
stringifiedCss.map.sources.map(function (filename) {
return originals[filename].getContentsAsString();
const file = originals[filename] || null;
return file && file.getContentsAsString();
});
// Compose the concatenated file's source map with source maps from the