To prevent the loader from overriding require, define, or requirejs you can instruct the loader
to use no conflict mode by providing it an alternative name for the various globals that are normally used.
require.unsee allows one to unload a given module. note The side-effects of that module cannot be unloaded.
This is quite useful, especially for test suites. Being able to unload run tests, mitigates many common memory leaks:
example:
define('my-app/tests/foo-test.js', ['qunit'], function(qunit) { let app; qunit.module('my module', { beforeEach() { app = new App(); } // forgot to `null` out app in the afterEach }); test('my app exists', function(assert) { assert.ok(app); })})
Note: To be able to take advantage of alternate define method name, you will also need to ensure that your
build tooling generates using the alternate. An example of this is done in the emberjs-build
project in the babel-enifed-module-formatter plugin.
wrapModules
It is possible to hook loader to augment or transform the loaded code. wrapModules is an optional method on the loader that is called as each module is originally loaded. wrapModules must be a function of the form wrapModules(name, callback). The callback is the original AMD callback. The return value of wrapModules is then used in subsequent requests for name
This functionality is useful for instrumenting code, for instance in code coverage libraries.