Transferred from: http://www.tuicool.com/articles/bmuaEb
Early this morning tasted seajs, found a very egg-ache thing, using the official demo of jquery is no problem,
Download the official latest version of jquery 2.1.1 found Console.log ($) returned NULL, baffled! Only ask for help Niang!
Yuber's note on GitHub, "methods for calling non-standard modules such as JQuery plug-ins directly"
However, this method in the 2.3 version seems to be no longer, the Seajs.modify method has been removed in this version!
https://github.com/seajs/seajs/issues/286
The standard module here refers to the definition of AMD and CMD.
Quote Yuber in a detailed answer
http://www.zhihu.com/question/20351507/answer/14859415
The following references to Yuber's reply will be more in-depth understanding
@lifesinger Yesterday was too tired, sorry. Later, I used RequireJs to solve the problem. In addition, I would like to ask:1. amd is not easy to get stuck in the UI? Why 2. is using NodeJs modules written in the same CMD specification as seajs cannot be called directly-I've probably looked at it as if the definition is not quite the same, This is also the problem, since the same specification is followed why the format is not the same,3. script written with regular global variables is shim configured, in var ejs = require (' Ejs ') will overwrite ejs (global) definition, but can be require (' Ejs ') directly, then ejs will be registered to window name. 4. is there any difference between a regular script and a SeaJs standard format and RequireJs conversion? In addition, feel requirejs automatic loading plug-in mechanism is very good.
@iahuAMD is executed on a load, and when many files are loaded at once, it means that a large number of scripts are executed at once, which may result in a UI card. The execution of the cmd is decentralized and therefore generally does not result in UI cards. The relationship between seajs and Node.js can be consulted in this document: After the #275shim configuration, require (' Ejs ') The resulting ejs is the global one ejs, can also be mounted on the window of ejs removed, such as Seajs.config ({ plugins: ["shim"], alias: { src: ' Path/to/ejs.js ', exports: function () { var ejs = window.ejs; window.ejs = undefined; return ejs } }) requirejs shim plugins, essentially and SeaJS is the same.
The methods mentioned above are outdated and have to continue to try other ways!
Method One:
Or Yuber the boss of the way "Seajs 2.1.1 removed seajs.modify, how to preload the CDN in jquery?" 》
https://github.com/seajs/seajs/issues/862
The whole article is mainly said not to be modified in the CMD mode in the module using jquery, Yuber boss is not recommended so, but still can achieve
However, the jquery file is not configured in the Seajs.config, is directly in the head header to introduce files, as usual, and then in the Seajs inside an event mechanism to trigger the global jquery object to the internal Module.exports object;
Seajs.on (' exec ', function (module) {if (Module.uri = = = Seajs.resolve (' jquery ')) {window.$ = Window.jquery = Module.ex Ports }});
Method Two:
Of course, according to the CMD definition to encapsulate a jquery, the method is very simple, as long as the source code to stick in, and then return to jquery object;
Define (function () {//jquery source code return $.noconflict ();});
This allows the introduction of files in the Seajs.config to be used within other modules, here to return why $.noconflict (), see the introduction of the school
Http://www.w3school.com.cn/jquery/core_noconflict.asp
Seajs.config ({base: "). /sea-modules/", alias: {" jquery ":" Jquery.js "}});
Define (function (Require, exports, module) {var $ = require ("jquery"); Exports.showobj = function () {Console.log ($); }});
Method Three:
Refer to Seajs official jquery encapsulation method
if (typeof module = = = "Object" && module && typeof Module.exports = = = = "Object") {Module.exports = JQ Uery;} else {if (typeof define = = = "function" && define) {define ("jquery", [], function () {return jquery ; } ); }}if (typeof window = = = "Object" && typeof window.document = = = "Object") {window.jquery = window.$ = JQuery; }
Https://github.com/seajs/examples
In the catalogue sea-modules/jquery there is a packaged version of 1.10;
https://github.com/seajs/seajs/issues/264
Seajs How to integrate jquery