8 javascript yui-compressor maven angularjs
我正在尝试使用samaxes minify maven插件在我的angularjs应用程序中缩小javascripts和css文件.我能够将所有js和css缩小并使用maven构建war文件,但在尝试打开应用程序URL时,我得到了Error: [$injector:unpr] Unknown provider: aProvider <- a我的应用程序无效.
下面我提供我的pom插件配置
<plugin>
<groupId>com.samaxes.maven</groupId>
<artifactId>minify-maven-plugin</artifactId>
<version>1.7.4</version>
<executions>
<execution>
<id>min-js</id>
<phase>prepare-package</phase>
<goals>
<goal>minify</goal>
</goals>
</execution>
</executions>
<configuration>
<charset>UTF-8</charset>
<skipMerge>true</skipMerge>
<cssSourceDir>myapp/styles</cssSourceDir>
<jsSourceDir>myapp/javascript</jsSourceDir>
<jsEngine>CLOSURE</jsEngine>
<closureLanguage>ECMASCRIPT5</closureLanguage>
<closureAngularPass>true</closureAngularPass>
<nosuffix>true</nosuffix>
<webappTargetDir>${project.build.directory}/minify</webappTargetDir>
<cssSourceIncludes>
<cssSourceInclude>**/*.css</cssSourceInclude>
</cssSourceIncludes>
<cssSourceExcludes>
<cssSourceExclude>**/*.min.css</cssSourceExclude>
</cssSourceExcludes>
<jsSourceIncludes>
<jsSourceInclude>**/*.js</jsSourceInclude>
</jsSourceIncludes>
<jsSourceExcludes>
<jsSourceExclude>**/*.min.js</jsSourceExclude>
</jsSourceExcludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<webResources>
<resource>
<directory>${project.build.directory}/minify</directory>
</resource>
</webResources>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
目录结构

我的控制器结构
'use strict';
angular.module('myApp').controller('MyController', function($scope, $filter, $location, $interval, ngTableParams, $modal, $transition, myService, $timeout) {
...
});
Run Code Online (Sandbox Code Playgroud)
Chrome控制台错误

是否samaxes缩小Maven插件支持涅槃angularjs应用程序还是需要使用任何其他的方法?
请帮助我在我的angularjs应用程序中缩小js和css.
你走在正确的轨道上。
请注意,当您缩小控制器的 JavaScript 代码时,其所有函数参数也将被缩小,并且依赖项注入器将无法正确识别服务。
可以通过使用依赖项名称(以字符串形式提供)注释函数来解决此问题,该名称不会被缩小。有两种方法可以做到这一点:
(1.)$inject在控制器函数上创建一个包含字符串数组的属性。例如:
function MyController($scope, $filter, $location, $interval, ngTableParams, $modal, $transition, myService, $timeout) {...}
MyController.$inject = ['$scope', '$filter', '$location', '$interval', 'ngTableParams', '$modal', '$transition', 'myService', '$timeout'];
Run Code Online (Sandbox Code Playgroud)
(2.) 使用内联注释,您不仅提供函数,还提供数组。在你的情况下,它看起来像:
angular.module('myApp').controller('MyController', ['$scope', '$filter', '$location', '$interval', 'ngTableParams', '$modal', '$transition', 'myService', '$timeout', function($scope, $filter, $location, $interval, ngTableParams, $modal, $transition, myService, $timeout) {
...
}]);
Run Code Online (Sandbox Code Playgroud)
有关更多信息,请查看本教程的“关于缩小的注释”部分。
| 归档时间: |
|
| 查看次数: |
12915 次 |
| 最近记录: |