Skip to content

Commit ae39b82

Browse files
committed
Work around sourcemap issues with banner option
Fixes #307
1 parent 7d26453 commit ae39b82

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

gruntfile.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
* license that can be found in the LICENSE file.
55
*/
66
module.exports = function(grunt) {
7-
var banner = [grunt.file.read('LICENSE'), '// @version ' + grunt.file.readJSON('package.json').version, ''].join(grunt.util.linefeed);
7+
var temporary = require('temporary');
8+
var tmp = new temporary.File();
89

910
// recursive module builder
1011
var path = require('path');
@@ -24,7 +25,7 @@ module.exports = function(grunt) {
2425
return modules;
2526
}
2627

27-
Polymer = readManifest('build.json');
28+
var Polymer = readManifest('build.json', [tmp.path]);
2829

2930
grunt.initConfig({
3031
karma: {
@@ -52,8 +53,8 @@ module.exports = function(grunt) {
5253
},
5354
uglify: {
5455
options: {
55-
banner: banner,
56-
nonull: true
56+
nonull: true,
57+
preserveComments: 'some'
5758
},
5859
Polymer: {
5960
options: {
@@ -131,8 +132,24 @@ module.exports = function(grunt) {
131132
});
132133
grunt.file.write(dest, JSON.stringify(destMap));
133134
});
134-
grunt.registerTask('default', ['concat_sourcemap', 'uglify', 'sourcemap_copy:polymer.concat.js.map:polymer.min.js.map', 'audit']);
135-
grunt.registerTask('minify', ['uglify']);
135+
136+
// Workaround for banner + sourceMap + uglify: https://github.com/gruntjs/grunt-contrib-uglify/issues/22
137+
grunt.registerTask('gen_license', function() {
138+
var banner = [
139+
'/* @license',
140+
grunt.file.read('LICENSE'),
141+
'@version ' + grunt.file.readJSON('package.json').version,
142+
'*/'
143+
].join(grunt.util.linefeed);
144+
grunt.file.write(tmp.path, banner);
145+
});
146+
147+
grunt.registerTask('clean_license', function() {
148+
tmp.unlinkSync();
149+
});
150+
151+
grunt.registerTask('default', ['minify', 'audit']);
152+
grunt.registerTask('minify', ['gen_license', 'concat_sourcemap', 'uglify', 'sourcemap_copy:polymer.concat.js.map:polymer.min.js.map', 'clean_license']);
136153
grunt.registerTask('docs', ['yuidoc']);
137154
grunt.registerTask('test', ['override-chrome-launcher', 'karma:polymer']);
138155
grunt.registerTask('test-buildbot', ['override-chrome-launcher', 'karma:buildbot']);

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"karma-script-launcher": "*",
1515
"karma-crbot-reporter": "*",
1616
"grunt-audit": "~0.0.1",
17-
"grunt-concat-sourcemap": "~0.3.0"
17+
"grunt-concat-sourcemap": "~0.3.0",
18+
"temporary": "~0.0.7"
1819
}
1920
}

0 commit comments

Comments
 (0)