Skip to content

Instantly share code, notes, and snippets.

@toolmantim
Last active December 13, 2015 18:58
Show Gist options
  • Save toolmantim/4958966 to your computer and use it in GitHub Desktop.
Save toolmantim/4958966 to your computer and use it in GitHub Desktop.
Various configurations to ensure newlines are preserved in minified Javascript files. Fork it and add another language/framework/compressor combination!
# Brunch - http://brunch.io/
#
# Using uglify-js-brunch - https://github.com/brunch/uglify-js-brunch
#
# Use the following settings in your Brunch configuration file
exports.config =
plugins:
uglify:
output:
beautify: true
indent_level: 0
Codekit - http://incident57.com/codekit/
Use the following settings in CodeKit's Preferences:
Indentiation: 0 spaces
Beautify: on
# Google Closure Compiler
#
# The only way to get Closure Compiler to include newlines is to use the PRETTY_PRINT option,
# but there's no way to supress indentation. The only workaround seems to be removing the
# indentation manually.
#
# Below is an example using the sed command to remove the indentation.
java -jar compiler.jar --formatting PRETTY_PRINT [script file path] | sed 's/^ *//'
// Grunt - http://gruntjs.com/
//
// Using grunt-contrib-uglify - https://npmjs.org/package/grunt-contrib-uglify
//
// Set the following uglify.options in your Gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
uglify: {
options: {
beautify: {
beautify: true,
indent_level: 0
}
}
}
});
};
// Node-minify https://npmjs.org/package/node-minify
//
// Use one of the following set of options when calling compressor.minify
new compressor.minify({
type: 'uglifyjs',
options: ['--beautify "indent-level=0"']
});
new compressor.minify({
type: 'yui-js',
options: ['--line-break 0']
});
# Rails 3 asset pipeline - http://rubyonrails.org/
#
# Add the following to your config/environments/production.rb
# Only run when Uglifier is available (i.e. the :assets bundler group)
if defined? Uglifier
config.assets.js_compressor = Uglifier.new(
output: {
# Add new lines
beautify: true,
# Don't add indentation
indent_level: 0
}
)
end
# Sinatra AssetPack - https://github.com/rstacruz/sinatra-assetpack
#
# Add the following to your assets configure block
js_compression :uglify,
output: {
# Add new lines
beautify: true,
# Don't add indentation
indent_level: 0
}
// UglifyJS 2 node library - https://github.com/mishoo/UglifyJS2
//
// Use the following options when calling UglifyJS.minify
var UglifyJS = require("uglify-js");
var result = UglifyJS.minify("[script file path]", {
output: {
beautify: true,
indent_level: 0
}
});
console.log(result.code);
# UglifyJS 2 cmd line tool - http://nodejs.org/ https://github.com/mishoo/UglifyJS2
#
# Use the following command line options with the uglifyjs command line tool
uglifyjs [script file path] --beautify "indent-level=0"
# YUI Compressor - http://yui.github.com/yuicompressor/
#
# Use the following command line options with the YUI compressor line tool
java -jar yuicompressor.jar --line-break 0 [script file path]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment