引用单个文件:
<script type="text/javascript" data-main="globle_config" src="require.js"></script>
globle_config.js
require.config({
baseUrl: "js", // 默认为requirejs所在的目录
urlArgs: "v=" + (new Date()).getTime(), // 加版本号消除requirejs的缓存配置文件
paths: {
"jquery" : ["http://libs.baidu.com/jquery/2.0.3/jquery.min","jquery-2.0.3.min"],
"css": "css.min"
},
shim: {
"jquery": { exports: "jquery", deps: ["css!../css/Komo-UI"]}
}
});
require(["jquery"],function(){
console.log("test requireJS successful!");
});
引用公共(多个)文件:
<script type="text/javascript" data-main="globle_config" src="require.js"></script>
<script type="text/javascript" src="app.js"></script>
globle_config.js
require.config({
baseUrl: "js", // 默认为requirejs所在的目录
paths: {
"jquery" : ["http://libs.baidu.com/jquery/2.0.3/jquery.min","jquery-2.0.3.min"],
"css": "css.min"
},
shim: {
"jquery": { exports: "jquery", deps: ["css!../css/Komo-UI"]}
}
});
app.js
require(["globle_config"],function(){
require(["jquery","css"],function(){
console.log("requireJS调用成功!");
});
});