taptapship / wiredep

Wire Bower dependencies to your source code.
MIT License
1.15k stars 142 forks source link

Change order of imports (devDependencies/optional dependencies) #204

Closed kennethlynne closed 8 years ago

kennethlynne commented 9 years ago

I want to change order of files imported, and I can specify y as a dependancy for x in overrides, but in my case I only want that to be the case in dev and I do not want y included in prod.

Related to #163

kennethlynne commented 9 years ago

In my case I solved it with https://www.npmjs.com/package/anysort, sorting bowerDeps.js. Maybe an idea to use that and let users provide sorting order patterns?

kennethlynne commented 9 years ago

This also did the trick:

  function sortDat(arr, patterns) {
    return patterns
      .reduce(function (result, pattern) {
        arr = arr.reduce(function (nonmatching, path) {
          if (minimatch(path, pattern)) {
            result.push(path);
            return nonmatching;
          }
          return nonmatching.concat([path]);
        }, []);
        return result;
      }, [])
      .concat(arr);
  }

  // Sort bower dependencies in the order of the patterns in this array, and leave the sorting order of the
  // non-matching intact
  var order = [
    '**/jquery/**',
    '**/lodash/**'
  ];

  bowerDeps.js = sortDat(bowerDeps.js, order);
schmkr commented 8 years ago

FWIW, my workaround for this was to define jquery to not have a main in overrides and then adding jquery script tag before <!-- bower:js -->.

    "overrides" : {
        "jquery" : {
            "main" : []
        }
    }
eddiemonge commented 8 years ago

Closing this as there are workarounds available