taptapship / wiredep

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

Output filenames in external file for production script marshalling #216

Closed daredevil82 closed 8 years ago

daredevil82 commented 9 years ago

Wiredep is great for development environments and projects that don't have to concern themselves with minimizing HTTP requests for resources. However, for most other projects, the lack of a centralized JSON file that contains the paths and script filenames is a major feature missing because this would greatly simplify the script marshalling build step where all JS files are concatenated and minified to one file.

Certainly, it is possible to write up a node script to parse the index.html file for the associated script resources, but this would be up to the project dev to implement, rather than being a wiredep feature.

I propose something like this:

  1. Add a -json flag to wiredep options and set it to true or path to saved file.
  2. After wiredep completes writing the script/link tags, it should output to a default/path file in a format like

    {
          js : [
            {
                 angular : {
                     path : "bower_components/angular/",
                     file : "angular.js"
                 }
             },
             {
                  jquery : {
                     path :  "bower_components/jquery/dist/",
                     file : "jquery.js"
                  }
             }
        ]
    }

    The output in the array would be in the same order as wiredep outputs to the html file.

This would simplify the third-party dependency concatenation during the build process and remove any requirement by the project developer/maintainer to explicitly maintain a file with the dependencies.

eddiemonge commented 8 years ago

But you can already easily do this on your own in about 1 line of code. wiredep already returns this information:

require('fs').writeFile(JSON.stringify(require('wiredep')({ src: 'index.html' }), null, 2));

This information is already provided programmatically. Many build tools already use this.