diff options
author | Oleg Gaidarenko <markelog@gmail.com> | 2013-08-16 09:48:00 -0400 |
---|---|---|
committer | Timmy Willison <timmywillisn@gmail.com> | 2013-08-16 09:48:00 -0400 |
commit | df67c1ab0963c6a05735e84f4088a0f6b7484b3d (patch) | |
tree | bcc4f498cee4e72f232dfa2d2f8ed4569fc95664 /build/tasks/uglify.js | |
parent | 70c9a0a13a56402724590f9450600fabb59e79a8 (diff) | |
download | jquery-df67c1ab0963c6a05735e84f4088a0f6b7484b3d.tar.gz jquery-df67c1ab0963c6a05735e84f4088a0f6b7484b3d.zip |
Move jQuery specific tasks to independent files. Close gh-1334.
Also:
* Confirm build task to the style guide
* Use grunt API to load jQuery specific tasks
* Add "use strict"; statements
Diffstat (limited to 'build/tasks/uglify.js')
-rw-r--r-- | build/tasks/uglify.js | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/build/tasks/uglify.js b/build/tasks/uglify.js new file mode 100644 index 000000000..7c1a01bec --- /dev/null +++ b/build/tasks/uglify.js @@ -0,0 +1,54 @@ +module.exports = function( grunt ) { + + "use strict"; + + var fs = require( "fs" ); + + // Work around grunt-contrib-uglify sourceMap issues (jQuery #13776) + grunt.registerMultiTask( "pre-uglify", function() { + var banner = this.options().banner; + + this.files.forEach(function( mapping ) { + // Join src + var input = mapping.src.map(function( file ) { + var contents = grunt.file.read( file ); + + // Strip banners + return contents + // Remove the main jQuery banner, it'll be replaced by the new banner anyway. + .replace( /^\/\*![\W\w]*?\*\/\n?/g, "" ) + // Strip other banners preserving line count. + .replace( /^\/\*!(?:.|\n)*?\*\/\n?/gm, function ( match ) { + return match.replace( /[^\n]/gm, "" ); + }); + }).join("\n"); + + // Write temp file (with optional banner) + grunt.file.write( mapping.dest, ( banner || "" ) + input ); + }); + }); + + // Change the map file to point back to jquery.js instead of jquery.pre-min.js. + // The problem is caused by the pre-uglify task. + // Also, remove temporary files. + grunt.registerMultiTask( "post-uglify", function() { + this.files.forEach(function( mapping ) { + var mapFileName = mapping.src[ 0 ]; + + // Rename the file to a temporary name. + fs.renameSync( mapFileName, mapping.dest); + grunt.file.write( mapFileName, grunt.file.read( mapping.dest ) + // The uglify task erroneously prepends dist/ to file names. + .replace( /"dist\//g, "\"" ) + // Refer to the source jquery.js, not the temporary jquery.pre-min.js. + .replace( /\.pre-min\./g, "." ) + // There's already a pragma at the beginning of the file, remove the one at the end. + .replace( /\/\/@ sourceMappingURL=jquery\.min\.map$/g, "" )); + }); + + // Remove temporary files. + this.options().tempFiles.forEach(function( fileName ) { + fs.unlink( fileName ); + }); + }); +}; |