Jsu*_*alv 9 javascript frontend amd requirejs
什么时候应使用paths与packages在RequireJS?是否有最好的做法,或者在我应该考虑使用其中一个的特定时间?
我跟着文档,我想出了这个:
// main.js
requirejs.config({
enforceDefine: true,
urlArgs: "bust=" + (new Date()).getTime(),
baseUrl: "./js",
waitSeconds: 7,
paths: {
"jquery": [
'jquery'
],
"underscore": [
'underscore'
],
"backbone": [
'backbone'
],
"handlebars": [
'handlebars'
]
},
shim: {
"underscore": {
deps: [],
exports: "_"
},
"backbone": {
deps: ["jquery", "underscore"],
exports: "Backbone"
},
"handlebars": {
deps: [],
exports: "Handlebars"
}
} // End shim
}); // End config
// List all files; use 'define()' and not 'require()' because of shim
define([
'jquery',
'underscore',
'backbone',
'handlebars'
], function ($, _, Backbone, Handlebars)
{
console.log("$: " + typeof $);
console.log("_: " + typeof _);
console.log("Backbone: " + typeof Backbone);
console.log("Handlebars: " + typeof Handlebars);
}
); // End define
Run Code Online (Sandbox Code Playgroud)
但是,我观看了Jesse Warden的视频(http://css.dzone.com/articles/video-basics-requirejs),他似乎在他的大部分代码中使用了这种风格:
// main.js
requirejs.config({
urlArgs: "bust=" + (new Date()).getTime(),
baseUrl: "./js",
waitSeconds: 7,
packages: [
'main',
{
name: 'jquery',
location: 'libs/jquery',
main: 'jquery'
},
{
name: 'underscore',
location: 'libs/underscore',
main: 'underscore'
},
{
name: 'backbone',
location: 'libs/backbone',
main: 'backbone'
},
{
name: 'handlebars',
location: 'libs/handlebars',
main: 'handlebars'
}
]
}); // End config
Run Code Online (Sandbox Code Playgroud)
那么这是正确的方法呢?我应该使用paths或packages?此外,还有一个modules配置.我modules什么时候使用?
| 归档时间: |
|
| 查看次数: |
5676 次 |
| 最近记录: |