目前我有几个html文件看起来像这样:
<!-- build:js({.tmp,app}) scripts/moduleX-scripts.js -->
<script src="scripts/moduleX/moduleXConfig.js"></script>
<script src="scripts/moduleX/featureX/controller.js"></script>
<script src="scripts/moduleX/featureX/service.js"></script>
<script src="scripts/moduleX/featureY/controller.js"></script>
<script src="scripts/moduleX/featureY/service.js"></script>
<!-- endbuild -->
<!-- build:js({.tmp,app}) scripts/moduleY-scripts.js -->
<script src="scripts/moduleY/moduleYConfig.js"></script>
<script src="scripts/moduleY/featureW/controller.js"></script>
<script src="scripts/moduleY/featureW/service.js"></script>
<script src="scripts/moduleY/featureZ/controller.js"></script>
<script src="scripts/moduleY/featureZ/service.js"></script>
<!-- endbuild -->
由于这是一个angular应用程序,我想使用ocLazyLoad来管理我的模块,所以我的配置看起来像这样:
angular.module('MyMainModule', [
{
name: 'moduleX',
files: [
'scripts/moduleX/moduleXConfig.js',
'scripts/moduleX/featureX/controller.js',
'scripts/moduleX/featureX/service.js',
'scripts/moduleX/featureY/controller.js',
'scripts/moduleX/featureY/service.js',
]
},
{
name: 'moduleY',
files: [
'scripts/moduleY/moduleYConfig.js',
'scripts/moduleY/featureW/controller.js',
'scripts/moduleY/featureW/service.js',
'scripts/moduleY/featureZ/controller.js',
'scripts/moduleY/featureZ/service.js',
]
}
])
是否有任何grunt插件会处理这个。js文件,并将files
数组替换为缩小和修订的版本?
您可以使用grunt-contrib-uglifyjs
来缩小您的文件。
grunt.initConfig({
uglify: {
moduleX: {
files: {
'scripts/moduleX.min.js': ['scripts/moduleX/*.js']
}
},
moduleY: {
files: {
'scripts/moduleY.min.js': ['scripts/moduleY/*.js']
}
}
}
});
你唯一需要做的改变就是在你的模块目录中包含一个声明你的模块的文件。例如,在scripts/moduleX
目录中,您将拥有以下文件:
// scripts/modeulX.js
angular.module('moduleX', []);