Concat scripts in order with Gulp

后端 未结 17 1476
后悔当初
后悔当初 2020-11-28 01:51

Say, for example, you are building a project on Backbone or whatever and you need to load scripts in a certain order, e.g. underscore.js needs to be loaded befo

17条回答
  •  春和景丽
    2020-11-28 02:31

    I'm in a module environnement where all are core-dependents using gulp. So, the core module needs to be appended before the others.

    What I did:

    1. Move all the scripts to an src folder
    2. Just gulp-rename your core directory to _core
    3. gulp is keeping the order of your gulp.src, my concat src looks like this:

      concat: ['./client/src/js/*.js', './client/src/js/**/*.js', './client/src/js/**/**/*.js']
      

    It'll obviously take the _ as the first directory from the list (natural sort?).

    Note (angularjs): I then use gulp-angular-extender to dynamically add the modules to the core module. Compiled it looks like this:

    angular.module('Core', ["ui.router","mm.foundation",(...),"Admin","Products"])
    

    Where Admin and Products are two modules.

提交回复
热议问题