11

Update: For anyone interested in using Brunch with AngularJS I've put together a seed project angular-brunch-seed

I'm using Brunch with AngularJS. AngularJS provides a module system so the need for importing file using commonJS / AMD is redundant. Is it possible to disable this feature for files in the /app directory? Essentially I would like it to compile files unaltered like it does for the /vendor directory.

So the preferred out come would be:

  joinTo:
    'js/app.js': /^app/
    'js/vendor.js': /^vendor/

With both js/app.js and js/vender.js containing compile files from each respective folder, but neither wrapped.

Does anyone have any ideas?

UPDATE The syntax has changed from when @jcruz answer. Here's the way to do this now.

In the end I went with a modified version of @jcruz answer.

exports.config =
  modules:
    definition: false
    wrapper: (path, data) ->
      """
(function() {
  'use strict';
  #{data}
}).call(this);\n\n
      """
  files:
    javascripts:
      defaultExtension: 'coffee'
      joinTo:
        'js/app.js': /^app/
        'js/vendor.js': /^vendor/

By default the "raw" wrapper does not include coffeescript's standard wrapper. By setting jsWrapper to:

wrapper: (path, data) ->
  """
(function() {
  'use strict';
  #{data}
}).call(this);
  """

files will be wrapped as expected.

Kyle Finley
  • 11,842
  • 6
  • 43
  • 64
  • hey thanks for updating this question with the new syntax. I just updated brunch and the old 'jsWrapper' syntax was not working. – jcruz Sep 10 '12 at 19:47

3 Answers3

13

This has changed to a module configuration now, as far as I can see: https://github.com/brunch/brunch/blob/stable/docs/config.md#modules

exports.config =
  paths:
    ...
  files:
    ...
  modules:
    wrapper: false
    definition: false
thasmo
  • 9,159
  • 6
  • 27
  • 32
5

The ability to disable the module wrapping was just recently added in https://github.com/brunch/brunch/commit/ec158cffd1b66d5db2093cf766000673aa0dd3a5

I dont believe the release w/ these features is on npm yet but you could just re-install brunch from the github repo

Once you do that Brunch, set jsWrapper to 'raw' in your config.coffee

Something like this...

exports.config =
  jsWrapper: 'raw'
  files:
    javascripts:
      defaultExtension: 'js'
      joinTo:
        'javascripts/app.js': /^app/
        'javascripts/vendor.js': /^vendor/

'brunch b' and the wrapping code should disappear

jcruz
  • 718
  • 6
  • 13
  • I ended up passing a function to wrap the files in the standard coffeescript wrapper, but other then that it works perfectly. Thank you! – Kyle Finley Jul 06 '12 at 22:41
4

As of (almost) 2017 Jan, it is imperative to declare npm enabled to false along with module settings. It took me a while to find out, though. (Found this via a GitHub issue). Hope this helps. Cheers.

Here is a working config file:

// See http://brunch.io for documentation.
module.exports = {
    files: {
      javascripts: {
        joinTo: {
          '/js/app.js': /^app/,
          '/js/vendor.js': /^(?!app)/
        }
      },
      stylesheets: {
        joinTo: 'css/app.css'
      }
    },

    paths: {
      public: '/priv/static'
    },

    npm: {
      enabled: false
    },

    modules: {
      wrapper: false,
      definition: false
    }
}
dsignr
  • 2,295
  • 2
  • 35
  • 45