Skip to content

Commit f667f33

Browse files
authored
Merge pull request #926 from homedepotlabs/sourcemaps_licensecomments
Source Maps with License Comments
2 parents db3d0b0 + e7400fe commit f667f33

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

build/jslib/build.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,12 +1428,12 @@ define(function (require) {
14281428
}
14291429

14301430
if (config.generateSourceMaps) {
1431-
if (config.preserveLicenseComments && config.optimize !== 'none') {
1431+
if (config.preserveLicenseComments && !(config.optimize === 'none' || config.optimize === 'uglify')) {
14321432
throw new Error('Cannot use preserveLicenseComments and ' +
1433-
'generateSourceMaps together. Either explcitly set ' +
1434-
'preserveLicenseComments to false (default is true) or ' +
1435-
'turn off generateSourceMaps. If you want source maps with ' +
1436-
'license comments, see: ' +
1433+
'generateSourceMaps together, unless optimize is set ' +
1434+
'to \'uglify\'. Either explicitly set preserveLicenseComments ' +
1435+
'to false (default is true) or turn off generateSourceMaps. ' +
1436+
'If you want source maps with license comments, see: ' +
14371437
'http://requirejs.org/docs/errors.html#sourcemapcomments');
14381438
} else if (config.optimize !== 'none' &&
14391439
config.optimize !== 'closure' &&

build/jslib/optimize.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,11 @@ function (lang, logger, envOptimize, file, parse,
247247
}
248248
}
249249

250+
if (config.generateSourceMaps && licenseContents) {
251+
optConfig.preamble = licenseContents;
252+
licenseContents = '';
253+
}
254+
250255
fileContents = licenseContents + optFunc(fileName,
251256
fileContents,
252257
outFileName,
@@ -406,6 +411,7 @@ function (lang, logger, envOptimize, file, parse,
406411
var result, existingMap, resultMap, finalMap, sourceIndex,
407412
uconfig = {},
408413
existingMapPath = outFileName + '.map',
414+
preamble = config.preamble || "",
409415
baseName = fileName && fileName.split('/').pop();
410416

411417
config = config || {};
@@ -414,6 +420,11 @@ function (lang, logger, envOptimize, file, parse,
414420

415421
uconfig.fromString = true;
416422

423+
if (config.preamble) {
424+
uconfig.output = {preamble: config.preamble};
425+
}
426+
427+
417428
if (config.generateSourceMaps && (outFileName || config._buildSourceMap)) {
418429
uconfig.outSourceMap = baseName + '.map';
419430

@@ -450,7 +461,7 @@ function (lang, logger, envOptimize, file, parse,
450461
} catch (e) {
451462
throw new Error('Cannot uglify file: ' + fileName + '. Skipping it. Error is:\n' + e.toString());
452463
}
453-
return fileContents;
464+
return preamble + fileContents;
454465
}
455466
}
456467
};

0 commit comments

Comments
 (0)