Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

feat(Grunt): Add source maps #2858

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified lib/closure-compiler/compiler.jar
Binary file not shown.
18 changes: 16 additions & 2 deletions lib/grunt/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ module.exports = {
.replace(/"NG_VERSION_MINOR"/, NG_VERSION.minor)
.replace(/"NG_VERSION_DOT"/, NG_VERSION.dot)
.replace(/"NG_VERSION_CDN"/, NG_VERSION.cdn)
.replace(/"NG_VERSION_CODENAME"/, NG_VERSION.codename);
.replace(/"NG_VERSION_CODENAME"/, NG_VERSION.codename)
.replace(/"NG_SOURCE_MAP"/, NG_VERSION.sourcemap);
if (strict !== false) processed = this.singleStrict(processed, '\n\n', true);
return processed;
},
Expand All @@ -98,12 +99,20 @@ module.exports = {
build: function(config, fn){
var files = grunt.file.expand(config.src);
var styles = config.styles;
//sourcemap
var NG_VERSION = grunt.config('NG_VERSION');
var sourcemapPrefix = '//@ sourceMappingURL=';
var sourceMappingURL = config.dest
.replace('build/', '')
.replace(/\.js$/, '-' + NG_VERSION.full + '.min.js.map');

NG_VERSION.sourcemap = sourcemapPrefix + sourceMappingURL;
//concat
var src = files.map(function(filepath){
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, NG_VERSION, config.strict);
if (styles) processed = this.addStyle(processed, styles.css, styles.minify);
//write
grunt.file.write(config.dest, processed);
Expand All @@ -121,17 +130,22 @@ module.exports = {


min: function(file, done) {
var NG_VERSION = grunt.config('NG_VERSION');
var minFile = file.replace(/\.js$/, '.min.js');
var mapFile = file.replace(/\.js$/, '-' + NG_VERSION.full + '.min.js.map');
shell.exec(
'java ' +
this.java32flags() + ' ' +
'-jar lib/closure-compiler/compiler.jar ' +
'--compilation_level SIMPLE_OPTIMIZATIONS ' +
'--language_in ECMASCRIPT5_STRICT ' +
'--source_map_format=V3 ' +
'--create_source_map ' + mapFile + ' ' +
'--js ' + file + ' ' +
'--js_output_file ' + minFile,
function(code) {
if (code !== 0) grunt.fail.warn('Error minifying ' + file);
grunt.file.write(mapFile, grunt.file.read(mapFile).replace('"sources":["build/','"sources":["'));
grunt.file.write(minFile, this.singleStrict(grunt.file.read(minFile), '\n'));
grunt.log.ok(file + ' minified into ' + minFile);
done();
Expand Down
1 change: 1 addition & 0 deletions src/angular.prefix
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
* @license AngularJS v"NG_VERSION_FULL"
* (c) 2010-2012 Google, Inc. http://angularjs.org
* License: MIT
* "NG_SOURCE_MAP"
*/
(function(window, document, undefined) {
1 change: 1 addition & 0 deletions src/loader.prefix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* @license AngularJS v"NG_VERSION_FULL"
* (c) 2010-2012 Google, Inc. http://angularjs.org
* License: MIT
* "NG_SOURCE_MAP"
*/
'use strict';
(
1 change: 1 addition & 0 deletions src/module.prefix
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
* @license AngularJS v"NG_VERSION_FULL"
* (c) 2010-2012 Google, Inc. http://angularjs.org
* License: MIT
* "NG_SOURCE_MAP"
*/
(function(window, angular, undefined) {