Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for source maps #42

Closed
wants to merge 2 commits 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
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ grunt.initConfig({
closurePath: '/src/to/closure-compiler',
js: 'static/src/frontend.js',
jsOutputFile: 'static/js/frontend.min.js',
sourceMapUrl: true,
maxBuffer: 500,
options: {
compilation_level: 'ADVANCED_OPTIMIZATIONS',
language_in: 'ECMASCRIPT5_STRICT'
language_in: 'ECMASCRIPT5_STRICT',
create_source_map: 'src.js.map'
}
}
}
Expand All @@ -42,6 +44,8 @@ grunt.initConfig({

If `jsOutputFile` property is set, the script will be minified and saved to the file specified. Otherwise it will be output to the command line.

If the `sourceMapUrl` property is set to a truthy value, the sourceMappingURL comment is appended to the generated JS file. If you pass this property as a string value, the sourceMappingURL will be set to that value. Otherwise, boolean true assumes the file name with a .map extension.

`maxBuffer` property

If the buffer returned by closure compiler is more than 200kb, you will get an error saying "maxBuffer exceeded". To prevent this, you can set the maxBuffer to the preffered size you want (in kb)
Expand Down
9 changes: 9 additions & 0 deletions tasks/closure-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ module.exports = function(grunt) {
done(false);
}

// Check to see if we should add the source map comment to end of file
if (data.sourceMapUrl && data.options.create_source_map) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where's the need for two options? Could you not just check for data.options.create_source_map?

if (typeof data.sourceMapUrl == 'boolean') data.sourceMapUrl = path.basename(data.jsOutputFile) + '.map';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't checking for "truthy", you should use if data.sourceMapUrl === true


fs.appendFile(data.jsOutputFile, '//# sourceMappingURL=' + data.sourceMapUrl, function (err) {
grunt.log.writeln('Could not add sourceMappingURL!');
});
}

if (stdout) {
grunt.log.writeln(stdout);
}
Expand Down