javascript - Brunch: How to correctly deal with AMD and vendor code? -


i amd-like syntax modules management in js. i'm trying figure out how can use require.js brunch. want achieve:

  1. all vendor code should concatenated in 1 file.
  2. exported vendor symbols should available in global scope(since 3rd-party code excpect find there).
  3. i want use require.js or almod module management.

the problem if load require.js of vendor scripts trying define anonymous module. here code snipped backbone reference:

if (typeof define === 'function' && define.amd) {     define(['underscore', 'jquery', 'exports'], function(_, $, exports) {       //...     }); 

}

as result, require.js complains anonymous module definition.

this why wrapping of vendor code disabled default in brunch. many vendor scripts have umd or own way of exposing api incompatible generic module wrapping, work out of box amd structure if left alone.

what may want organize vendor scripts separate directories ones need wrapping brunch , ones don't; vendor , vendor-wrapped. using default conventions settings, brunch wrap scripts in vendor-wrapped , not ones in vendor. can concatenate them both (based on your prior question's example):

      jointo:           'js/vendor.js': /^vendor(-wrapped)?[\\/](?!mocha|chai|sinon|sinon-chai)/ 

there still possibility you'll encounter vendor scripts structured in such way incompatible amd, when wrapped, , in cases choices either not use libs, work authors them updated, or maintain own modifications make them compatible project.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -