Uglify breaks ember?


I’m using grunt-contrib-uglify (through lineman.js) to compile my Ember code and it doesn’t work. I see no errors, but nothing get rendered. Looking at the console, I notice Ember.TEMPLATE[“index”] for example is undefined. Can uglify break ember/handlebars? anyone had this issue?


Uglify can absolutely break Ember (and any other code) depending on the options you choose. Uglify will sometimes attempt to rename global variables or methods, which can cause issues. I try to keep the compression options modest and my code works just fine. Here’s my options if you’d like a reference.

	compress: {
		global_defs: {
			DEBUG: false,
			RELEASE: true
		sequences: true,
		properties: true,
		drop_debugger: true,
		unsafe: false,
		conditionals: true,
		comparisons: true,
		evaluate: true,
		booleans: true,
		dead_code: true,
		loops: true,
		unused: true,
		hoist_funs: false,
		hoist_vars: false,
		if_return: true,
		join_vars: true,
		cascade: true,
		warnings: true,
		negate_iife: false,
		pure_getters: false,
		pure_funcs: null,
		drop_console: true
	mangle: true,
	preserveComments: false,
	report: 'gzip',
	screw_ie8: true

I have to mention that you should only be minifying your code. Don’t minify the Ember code; use the already minified version.

Thanks! Why is that I shouldn’t minify ember by myself?

Library vendors typically do their own minification because they know more about their code and are more likely to know exactly what compression options will/won’t break their code. Also, they run their minified code through their test suite, which you likely don’t do. In short: don’t worry about potentially breaking code that isn’t yours; just let the Ember team take care of their own code.

EDIT: I should mention, however, that I do some minification of vendor scripts. I do this because I concatenate all my scripts together and some libraries aren’t minified. But I only do whitespace minification, which is almost guaranteed not to break anything. Here’s my Uglify options for that:

	mangle: false,
	preserveComments: 'some', // keep licensing comments
	screw_ie8: true

Yes! I too want to concatenate all files together. But using the minified version of vendor script and using your config for that sounds good. Thanks!