javascript - requireJS why does each define has to be in different file? -
i using requirejs in sample demo app. code:
require({ paths: { todomodel: '/scripts/todomodel.min', todo: '/scripts/todo.min', todoservice: '/scripts/todoservice.min' } }, ['todo'], function (todo) { ko.applybindings(new todo(), $('#todo')[0]); } );
i know need of files app loads. want combine todomodel, todo , todoservice 1 file , yet define
them separate this:
define('todomodel', [], function () { todomodel = function (data) { ko.mapping.fromjs(data, {}, this); } return todomodel; });
all moment in separate files can see in paths attribute.
requirejs not require define
calls in different files. it's in development "one file, 1 module (i.e. 1 define
)" works pretty well. in fact, requirejs optimizer (r.js
) combines multiple define
calls 1 file during optimization. no problem there.
the setup show in question looks me development setup. normally, in development have requirejs load modules separate files, not minified. (your example suggest loading midified code.) deployment, use r.js
minify , concatenate various modules one file requirejs loads.
based on show in question, if did not use minified files you'd able use configuration this:
{ baseurl: "/scripts" }
and requirejs able find individual modules on basis of names because not have .min
in names.
Comments
Post a Comment