r.js

Most Efficient Multipage RequireJS and Almond setup

≯℡__Kan透↙ 提交于 2019-11-26 23:54:31
问题 I have multiple pages on a site using RequireJS, and most pages have unique functionality. All of them share a host of common modules (jQuery, Backbone, and more); all of them have their own unique modules, as well. I'm wondering what is the best way to optimize this code using r.js. I see a number of alternatives suggested by different parts of RequireJS's and Almond's documentation and examples -- so I came up with the following list of possibilities I see, and I'm asking which one is most

Dynamic require in RequireJS, getting “Module name has not been loaded yet for context” error?

无人久伴 提交于 2019-11-26 15:53:53
Is there a way to define a module that "dynamically" load other modules in RequireJS? If yes, how the optimizer (r.js) understands how/when a module has to be included? For example, let dynModules a module which defines name/path pairs: define([], function () { return ['moduleA', 'moduleB']; // Array of module names }); Another module is going to load modules dynamically, based on the array. This will not work : define(['dyn_modules'], function (dynModules) { for(name in dynModules) { var module = require(path); // Call RequireJS require } // ... }); ... gives me: Uncaught Error: Module name

Dynamic require in RequireJS, getting “Module name has not been loaded yet for context” error?

人走茶凉 提交于 2019-11-26 04:39:09
问题 Is there a way to define a module that \"dynamically\" load other modules in RequireJS? If yes, how the optimizer (r.js) understands how/when a module has to be included? For example, let dynModules a module which defines name/path pairs: define([], function () { return [\'moduleA\', \'moduleB\']; // Array of module names }); Another module is going to load modules dynamically, based on the array. This will not work : define([\'dyn_modules\'], function (dynModules) { for(name in dynModules) {