Brunch: how to wrap vendor code in AMD modules?

坚强是说给别人听的谎言 提交于 2019-12-11 11:59:40

问题


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'

回答1:


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



来源:https://stackoverflow.com/questions/29920466/brunch-how-to-wrap-vendor-code-in-amd-modules

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!