简体   繁体   中英

Brunch: how to wrap vendor code in AMD modules?

I want all vendor code to be wrapped in AMD modules. I have defined this section in my config.coffee:

modules:
    wrapper: 'amd'
    definition: 'amd'

But it seems like brunch uses AMD optimizer only for 'app' folder files. All vendor js files where concatinated without any r.js-like preprocessing(no module names added in "define(...)" statements). As a result, Almond(it's almost the same as RequireJS) complains about anonymous module definition during vendor file executing.

Here is my full config:

exports.config =

  paths:
    public: 'public'

  files:
    javascripts:
      defaultExtension: 'js'

      joinTo:
        'js/app.js': /^app/
        'js/vendor.js': /^vendor[\\/](?!mocha|chai|sinon|sinon-chai)/
        'js/tests.js': /^test/
        'js/tests-vendor.js': /^vendor[\\/](?=mocha|chai|sinon|sinon-chai)/

      order:
        before: [
          'bower_components/almond/almond.js',
          'bower_components/jquery/jquery.js',
          'bower_components/lodash/dist/lodash.underscore.js'
        ]

    stylesheets:
      defaltExtension: 'less'

      joinTo:
        'css/styles.css': /^(vendor[\\/](?!mocha|chai|sinon|sinon-chai)|app)/
        'css/tests-vendor.css': /^(vendor[\\/](?=mocha|chai|sinon|sinon-chai))/

    templates:
      defaultExtension: 'hbs'
      joinTo: 'js/app.js'

  modules:
    wrapper: 'amd'
    definition: 'amd'

You can change conventions.vendor in your config to something that won't match your vendor files in order to enable module wrapping.

https://github.com/brunch/brunch/blob/master/docs/config.md#conventions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM