How can I disable require.js at runtime?

My team and I have an AngularJS application that does not use RequireJS but loads in the context of an existing site that uses RequireJS. During the build process, I minimize / merge all our scripts into one JS file, which includes certain vendor libraries, such as Lodash, Moment, etc.

Starting a site isolated from the parent is fine, but in the context of the parent application, I get a well-documented error :

Uncaught Error: Mismatched anonymous define() module: function () { return _; }

I have no control over the parent application, is there a way at runtime to disable "RequireJS" or configure it to ignore my scripts?

The current solution we have is to modify the vendor libraries and remove the AMD code, but this is undesirable because we use Bower (with grunt-bower-install ) and would like to just update the dependencies automatically, rather than relying on manual processes and user-defined ones khaki.

+4
source share
1 answer

An approach that could be considered if you are sure that you have all the relevant script dependencies under control is to hide the function defineat the beginning of your mini-scripts / concatenated scripts.

For example, at the beginning of the mini-scripts, do the following:

var __origDefine = define;
define = null;

And at the end of the mini scripts:

define = __origDefine;
+6
source

Source: https://habr.com/ru/post/1548405/


All Articles