lvbreda / Meteor_angularjs

279 stars 42 forks source link

UglifyJS breaks deploy #5

Closed truemagic-coder closed 12 years ago

truemagic-coder commented 12 years ago

On deploy UglifyJS breaks Meteor-Angular: UglifyJS mangles $scope to a short variable name and thus breaks Angular controllers.

Error in JS Console: Unknown provider: eProvider <- e

Example (dev):

angular.module('controllers', []).controller('home', function($scope) {
   $scope.Players = new Meteor.AngularCollection("players", $scope, false);
   $scope.players = $scope.Players.find({});
});

Example (prod)

angular.module("controllers",[]).controller("home",function(e){e.Players=new Meteor.AngularCollection("players",e,!1),e.players=e.Players.find({})})
jasonkuhrt commented 12 years ago

Yup, there are angularjs docs to solve this using commented provider names (placed immediately under controller function names) but only in reference to google's closure minifer. For uglifyjs support I've used this less agrssive but working minifying strategy:

uglifyjs --overwrite --no-copyright --no-mangle --verbose path/main.js

jasonkuhrt commented 12 years ago

Uglifying is done within core:

https://github.com/meteor/meteor/blob/master/app/lib/bundler.js#L387

Fixing this isn't a one-liner it seems.

lvbreda commented 12 years ago

You can deploy with the --debug flag , this will disable uglify.

jasonkuhrt commented 12 years ago

@lvbreda thanks for the tip

jasonkuhrt commented 12 years ago

Why is it re-opned?

truemagic-coder commented 12 years ago

@lvbreda & @jasonkuhrt - Thanks!

ghost commented 11 years ago

Is there a good way to then minify the JS or must we do this using a third-party minifying engine?

tsenying commented 11 years ago

To survive minification, injected dependencies must be annotated. See the "Dependency Annotation" section here: http://docs.angularjs.org/guide/di

In the above example, it would look like:

angular.module('controllers', []).controller('home', ['$scope', function($scope) {
  ...
}]);
truemagic-coder commented 11 years ago

@tsenying That works - thanks - but minification is still breaking the app.

xiphias commented 11 years ago

A solution for the todos example:

https://github.com/lvbreda/Meteor_angularjs/pull/13/files

yngvark commented 11 years ago

Relevant solution for people using Grunt: http://stackoverflow.com/questions/17238759/angular-module-minification-bug