6

目前我有一些看起来像这样的 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 -->

由于这是一个角度应用程序,我想使用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用缩小和修订版本替换数组?

4

1 回答 1

0

你可以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', []);
于 2014-11-19T19:19:41.293 回答