2

Here's what I have in my app.js -

var app = angular.module("app", []);

And in my controller.js, I have -

app.service("Store", function() {
this.products = { item: "apple" };
});
app.controller("AppCtrl", function ($scope, Store) {
$scope.products = Store.products;
})

When I run it thru ngmin, I get this -

var app = angular.module('app', []);app.service('Store', function () {
  this.products = { item: 'apple' };
});
app.controller('AppCtrl', function ($scope, Store) {
  $scope.products = Store.products;
});

As you can see, it didn't annotate the dependencies correctly. However, if I have var app = angular.module("app", []); in controller.js, it works just fine -

var app = angular.module('app', []);
app.service('Store', function () {
  this.products = { item: 'apple' };
});
app.controller('AppCtrl', [
  '$scope',
  'Store',
  function ($scope, Store) {
    $scope.products = Store.products;
  }
]);

How do I make ngmin work with separate files?

4

1 回答 1

1

ngmin官方文档指出

理想情况下,您应该连接所有文件,然后对连接的文件运行一次 ngmin。

我不确定,但我认为这是ngmin 使用的库astral-angular-annotate的技术限制。模块声明过于严格。

在我工作的地方,在我们的 Gruntfile 中,我们首先使用grunt/concat连接所有文件,然后在生成的文件上运行grunt/ngmin。因此,我们只需要<script>在 webapp 的主体中包含一个元素,这非常方便。

于 2013-09-12T17:05:03.837 回答