将供应商javascript加载为模块

时间:2013-09-17 20:09:03

标签: brunch

我正在使用Brunch构建的应用程序。我想加载一些供应商提供的javascript作为模块,以便我可以require在我的代码中,而不是依赖于全局变量。 是否有某种方法可以执行此操作,而无需将所有供应商代码复制到我的app目录中?

我尝试创建了一个vendorlib目录,但早午餐看起来并不像appvendor。我也尝试制作一个vendor/modules目录,但早午餐似乎没有包装vendor下的任何内容(即使我说服它将这些文件与app下的其他模块文件组合在一起。)

*" some"我现在正在做的是Chaplin,Backbone和Underscore。如果我让那些工作,我会稍后再搬。

2 个答案:

答案 0 :(得分:4)

您可以覆盖config.modules.wrapper并将其换行,例如,vendor/modules目录中的所有文件。或者,您可以添加更多由早午餐处理的目录到config.paths.watched

答案 1 :(得分:2)

对于那些跟在家里的人来说,这就是我的config.coffee最终的样子:

  paths:
    watched: ['app','vendor','test','vendorlib']
  files:
    javascripts:
      joinTo:
        'javascripts/app.js': /^app/
        'javascripts/vendor.js': /^vendor/
        'test/javascripts/test.js': /^test[\\/](?!vendor)/
        'test/javascripts/test-vendor.js': /^test[\\/](?=vendor)/
      order:
        # Files in `vendor` directories are compiled before other files
        # even if they aren't specified in order.before.
        before: [
          'vendor/scripts/console-polyfill.js',
        ]
        after: [
          'test/vendor/scripts/test-helper.js'
        ]

    stylesheets:
      joinTo:
        'stylesheets/app.css': /^(app|vendor)/
        'test/stylesheets/test.css': /^test/
      order:
        after: ['vendor/styles/helpers.css']

    templates:
      joinTo: 'javascripts/app.js'

  modules:
    nameCleaner: (path) ->
      path.replace(/^(app|vendorlib)\//, '')

这允许我使用支持加载为模块的供应商的模块填充vendorlib目录。我目前有Chaplin,jQuery和Backbone。我不得不重命名它们,不包括版本号。

相关问题