The modules in Seajs obey the CMD specification by default, but in reality there are a lot of common JavaScript libraries such as jQuery, underscore, etc. Using the shim plugin, these ordinary JS files can be converted to a CMD module, which can be used normally in SEAJS.
Seajs.config ({ plugins: [' Shim ']}); |
Once activated, alias
configuration items can be configured to accept them shim Object
.
Seajs.config ({ //Activate shim plugin plugins: [' shim '], //shim config Item alias: { //jquery shim configuration ' jquery ': { src: ' lib/jquery-1.9.1.min.js ', exports: ' jquery ' }, //jquery.easing plugin's shim configuration ' Jquery.easing ': { src: ' lib/jquery.easing.1.3.js ', deps: [' jquery ']}}} ); |
shim Object
shim Object
is an object:
' key ': { src:string, deps:array, exports:string | Function } |
src
is a string that represents the file path.
deps
is an array that specifies the module dependency .
exports
Indicates require(key)
which global variable should be returned, such as jquery, which returns a jQuery
global variable. exports
It can also be a function:
' jquery ': { src: ' lib/jquery-1.9.1.min.js ', exports:function () { return jquery.noconflict ();} } |
With the shim plugin, you can load any non-CMD module.
Description: Generally used in config, first activate plugins: [' Shim '], and then configure the plugins to be referenced in alias, such as jquery.
Original http://www.k68.org/?p=1192
Seajs Shim Plugin: The difference between a plug-in that solves a non-CMD specification and sea