如何在不专门按顺序设置每个文件的情况下将 concatenation/uglification 与 AngularJS 一起使用

How to use concatenation/uglification with AngularJS without specifically setting each file in an order

我正在使用 AngularJS 构建一个项目,我希望使用 Grunt 和 grunt-contrib-concat(或类似的东西)将我所有的 angular 组件连接到一个文件中。

AngularJS 组件需要按顺序连接,以便具有模块声明的文件位于引用这些模块的文件之前。

看起来,如果您在 Grunt 任务中指定每个单独的文件,它将使用指定它们的顺序。但是,我希望找到一个解决方案,让我配置整个文件目录树的排序规则,这样我就不需要指定单个文件。

理想情况下,我希望程序遍历文件树并首先加载树中较高的文件。然后我可以使用这样的结构:

moduleFolder
  -> controllerFolder
      -> example.ctrl.js
      -> exampleAlternate.ctrl.js
  -> directiveFolder
      -> example.directive.js
  -> exampleModuleDeclaration.js

任何人都可以建议如何实现这一点,或者可以接受的 AngularJS 串联方式是什么?

'use strict';

module.exports = 函数(咕噜声){

grunt.initConfig({
    distFolder: '../scripts',
    pkg: grunt.file.readJSON('package.json'),
    concat: {
        options: {
            separator: ';'
        },
        scripts: {
            src: [
                '../app.js',
                '../controllers/*.js',
                '../controllers/*/*.js',
                '../services/*.js',
                '../directives/*.js',
                '../filters/*.js',
                '../factories/*.js'
            ],
            dest: '<%= distFolder %>/file_name.js'
        }
    }
});
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.registerTask('default', ['concat']);

};

试试这个并记住文件夹结构。它保存到脚本文件夹