configurationbrunch

Why brunch compile everything it found when using function in joinTo


I don't understand why BrunchJS compile all files (in bower_components) when i use a function like this (CoffeeScript):

modules = ['i18n', 'pager', 'core', 'module-comment']

javascripts:
  joinTo: 
    # Main
    '/js/master.js': () ->
      paths = ['bower_components/bootstrap/**/*', 'app/**/*']
        for o in modules 
        fs.exists '../../../../workbench/dynamix/' + o, (exists) ->
          if exists
            paths.push '../../../../workbench/dynamix/' + o + '/public/public/**/*'
          else
            paths.push '../../../../vendor/dynamix/' + o + '/public/public/**/*'
      return paths

I want to test if some path exist, if yes put the complete path in a variable to return it to joinTo. I have successfuly get files in workbench/vendor but it get some undesired files from bower_components (don't specified?!)

I would like to optimize this :

javascripts:
  joinTo: 
    # Main
    '/js/master.js':   
      'bower_components/bootstrap/**/*'
      '../../../../workbench/dynamix/i18n/public/public/**/*'
      '../../../../workbench/dynamix/pager/public/public/**/*'
      '../../../../vendor/dynamix/core/public/public/**/*'
      '../../../../workbench/dynamix/module-comment/public/public/**/*'
      '../../../../workbench/dynamix/module-love-live-music/public/public/**/*'
      '../../../../workbench/dynamix/module-rating/public/public/**/*'
      '../../../../workbench/dynamix/module-registration/public/public/**/*'
      'app/**/*'

I'm sorry i didn't find documentation to use function in joinTo.

Thanks


Solution

  • A function in a joinTo should take a file path as an argument and return true if the path should be included, false if not. This is described in the anymatch documentation.

    Your function appears to always return a truthy value, meaning every path Brunch is watching will be included.

    What you might have intended to do is use an IIFE, so the return value of the function (invoked during initial code evaluation) gets assigned to the joinTo. In coffeescript you can accomplish this easily using the do keyword, so instead of starting off your function definition with () -> it'd be do -> instead.