paths
をいつ使うべきですか?これにはベストプラクティスがあるのですか、それとも1つを他のものよりも優先して使用することを検討すべき特定の時間がありますか?
RequireJS:「パス」と「パッケージ」のどちらを使用するか
私はドキュメントを追っていると私はこの思い付いた:しかし、私はジェシーワーデン(http://css.dzone.com/articles/video-basics-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
:
// 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
これは適切な方法ですか? paths
またはpackages
を使用する必要がありますか?また、modules
設定があります。 modules
はいつ使用しますか?
私の限られた経験から、あなたはdev jqueryでパッケージを使用する必要があります。そうでなければ、core.jsや他の依存関係をjquery /ではなくbaseUrl /からロードできません。 –