diff --git a/lib/grunt/utils.js b/lib/grunt/utils.js index 204db413ecf2..c0a825bd2c5a 100644 --- a/lib/grunt/utils.js +++ b/lib/grunt/utils.js @@ -124,8 +124,9 @@ module.exports = { }, - process: function(src, NG_VERSION, strict){ + process: function(src, NG_VERSION, fileName, strict){ var processed = src + .replace(/"NG_FILENAME"/g, fileName) .replace(/"NG_VERSION_FULL"/g, NG_VERSION.full) .replace(/"NG_VERSION_MAJOR"/, NG_VERSION.major) .replace(/"NG_VERSION_MINOR"/, NG_VERSION.minor) @@ -146,7 +147,7 @@ module.exports = { return grunt.file.read(filepath); }).join(grunt.util.normalizelf('\n')); //process - var processed = this.process(src, grunt.config('NG_VERSION'), config.strict); + var processed = this.process(src, grunt.config('NG_VERSION'), this.extractFileName(config.dest), config.strict); if (styles) { processedStyles = this.addStyle(processed, styles.css, styles.minify); processed = processedStyles.js; @@ -164,23 +165,30 @@ module.exports = { } }, - singleStrict: function(src, insert){ return src .replace(/\s*("|')use strict("|');\s*/g, insert) // remove all file-specific strict mode flags .replace(/(\(function\([^)]*\)\s*\{)/, "$1'use strict';"); // add single strict mode flag }, + extractFileName: function(path) { + return path.match(/[^\/]+$/)[0]; + }, sourceMap: function(mapFile, fileContents) { var sourceMapLine = '//# sourceMappingURL=' + mapFile + '\n'; return fileContents + sourceMapLine; }, + fileToMinFile: function(fileName, minFileName, fileContents) { + return fileContents.replace(fileName, minFileName); + }, min: function(file, done) { var classPathSep = (process.platform === "win32") ? ';' : ':'; + var fileName = this.extractFileName(file); var minFile = file.replace(/\.js$/, '.min.js'); + var minFileName = this.extractFileName(minFile); var mapFile = minFile + '.map'; var mapFileName = mapFile.match(/[^\/]+$/)[0]; var errorFileName = file.replace(/\.js$/, '-errors.json'); @@ -212,6 +220,10 @@ module.exports = { // move add use strict into the closure + add source map pragma grunt.file.write(minFile, this.sourceMap(mapFileName, this.singleStrict(grunt.file.read(minFile), '\n'))); + + // change comment header filename to minified filename + grunt.file.write(minFile, this.fileToMinFile(fileName, minFileName, grunt.file.read(minFile))); + grunt.log.ok(file + ' minified into ' + minFile); done(); }.bind(this)); diff --git a/src/angular.prefix b/src/angular.prefix index 728fb1bc3f36..266f9495c783 100644 --- a/src/angular.prefix +++ b/src/angular.prefix @@ -1,5 +1,6 @@ -/** - * @license AngularJS v"NG_VERSION_FULL" +/** + * @license "NG_FILENAME" + * AngularJS v"NG_VERSION_FULL" * (c) 2010-2015 Google, Inc. http://angularjs.org * License: MIT */ diff --git a/src/loader.prefix b/src/loader.prefix index d4ff4e4dcd47..4c653df6a96b 100644 --- a/src/loader.prefix +++ b/src/loader.prefix @@ -1,5 +1,6 @@ /** - * @license AngularJS v"NG_VERSION_FULL" + * @license "NG_FILENAME" + * AngularJS v"NG_VERSION_FULL" * (c) 2010-2015 Google, Inc. http://angularjs.org * License: MIT */ diff --git a/src/module.prefix b/src/module.prefix index 38d88eb98231..aac59e57fb39 100644 --- a/src/module.prefix +++ b/src/module.prefix @@ -1,5 +1,6 @@ /** - * @license AngularJS v"NG_VERSION_FULL" + * @license "NG_FILENAME" + * AngularJS v"NG_VERSION_FULL" * (c) 2010-2015 Google, Inc. http://angularjs.org * License: MIT */