Last Updated: February 25, 2016
·
549
· webspinner

Require JS and Minifiers

It is likely the case that at some point you will use require js async style syntax. But lots of libraries (like ace.js for instance) use the commonjs style syntax for defining their modules. This generally works fine since requirejs will statically analyze the incoming script and detect the dependencies required to actually load the scripts contents. The problem comes in when you deploy to production and minify your code, now all the places that once said:

define(function(require){
  something = require("something");...

will now say:

define(function(e){x = e;...

so the incoming file will no longer match the requirements to have it's dependencies loaded. To get around this make sure to add "require" to the list of reserved words so it is not mangled on request.