requirejs's Introduction
1、jqueryjs主要部分 ① 首先依赖文件 jquery.js ② 配置文件 config.js <script type="text/javascript" src="require.js" data-main="config.js"></script> config.js: requirejs.config({ baseUrl: './', //js 依赖文件基础路径 paths : { jquery :'lib/jquery.min' } shim:{ 'path/unAmd':{ //'path/unAmd' 为非AMD规范的js库 在 jqueryjs中与AMD规范同样引用 exports导入对应方法(一个) exports:'funcName', } 'path/unamd2':{ //导入多个方法时 init: function(){ name1:'funcname1', name2:'funcname2' } } } }); ③ define 定义AMD 规范库,返回对象即被引用时的参数 define(function(){ return { name:'ami', work:function(){ 'work'; } } }) ④ requirejs 可调用AMD或非AMD规范的库(需要特殊处理) requirejs(['a','b'],function(a,b){ //a、b 为 define 返回对象 }) ⑤ require 可以调用define的库或paths中的库 require(['jquery'],function(jq){ jq 即为jquery对象 或者 require('jquery') }); 注: 1)requirejs同require,但是requirejs不能访问 path定义的值,相反require 可以访问path定义的(js文件或路径)还有其他的js文件,所以建议使用require而不是requirejs 2)require依赖必须是直接指向js文件,而shim属性名必须和require依赖名相同(通过path定义文件路径或文件)
requirejs's People
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.