Search code examples
pluginsfingerprintbrunch

How to rename the final generated file in a Brunch plugin?


I'm developing a plugin for BrunchJS and i don't understand everything.

https://github.com/dlepaux/fingerprint-brunch Inspirated by github.com/mutewinter/digest-brunch and github.com/jgallen23/grunt-hash

Concept : Rename output filename and write it into a manifest with a key (to get the real filename).

Exemple : In this config file i want to make a /js/master.js file.

The goal of this plugin is to rename this filename like this : master.[hash].js

Next write this in a manifest : {'/js/master.js' : '/js/master.[hash].js'}

I hope you will help me to understand how do what i what to do.

exports.config =
  paths:
    public: './../public'
    compass: './config.rb'
    watched: ['app']

  files:
    javascripts:
      joinTo: 
        '/js/master.js': /^(bower_components[\/\\]bootstrap-sass-twbs|bower_components[\/\\]bootstrap-datepicker|app)/

        #'/js/vendor/response.js': /^(bower_components[\/\\]responsejs)/
        #'/js/vendor/head.min.js': /^(bower_components[\/\\]headjs)/
        #'/js/vendor/jquery.min.js': /^(bower_components[\/\\]jquery)/
        #'/js/vendor/media.match.min.js': /^(bower_components[\/\\]media-match)/

  modules:
    wrapper: false
    definition: false

  conventions:
    # we don't want javascripts in asset folders to be copied like the one in 
    # the bootstrap assets folder
    assets: /assets[\\/](?!javascripts)/

  plugins:
    cleancss:
      keepSpecialComments: 0
      removeEmpty: true
    sass:
      debug: 'comments' # or set to 'debug' for the FireSass-style output
    fingerprint:
      manifest: '../../assssssets.json'
      targets: ['/js/master.js']

In this configuration file, at the bottom, you see fingerprint, here you will set what file in config.files you want to hash, because i imagine you don't what to put a hash everywhere !

My problem now is, that i don't know how rename the final file... So how i can do that ? - By renaming the final file ? - By duplicating the master.js (generated) and rename it ?

I must do all that in the onCompile function? or teardown (at the end) ?

I have only this doc : github.com/brunch/brunch/blob/stable/docs/plugins.md

I'm confused..

Thank you


Solution

  • Take a look at the approach of plugin digest-brunch: https://github.com/mutewinter/digest-brunch

    It uses onCompile and lots of code to cover all the edge cases.

    That should do the trick.