Frage

I have two apps that use RequireJS. One uses the other as a plugin, a module of sorts if you will. The plugin/module is optimised already using r.js.

When I run the app on my server everything works fine, in this state the app isn't optimised yet, only the plugin/module.

When I go to optimise the app via r.js and I include the plugin/module r.js throws an error because it can't find files that the plugin/module uses but ultimately gets bundled in when the plugin/module gets optimised.

So how do I get round this? I think I have the following options:

  1. As I build my main app I include the unoptimised plugin/module and optimise it all at once.
  2. I add all the URLs in the optimised plugin/module to the config and point them to :empty, but that's going to be a ball ache as those paths are dynamic.

So what else can I do? Is there a way to tell r.js to either:

  1. Don't bother looking for the required paths in my optimised plugin/module.
  2. Somehow compile my plugin/mobile but remove all traces of define and require from it, thus making it self contained, if that's even possible.
War es hilfreich?

Lösung

So I got around the issue by including my plugin/module as a dependancy rather than part of the application.

Since it's a good idea to have a main config file for your app, I told r.js to use this but then spoofed the URL for my plugin/module to the special empty: value.

This then stopped r.js trying to find all the dependancies of the already optimised plugin/module and allowed me to include it as a dependancy; all is now well.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top