여기 내 요구 사항 인 백본과 핸들 바를 사용합니다.요구 사항, 아몬드, 백본, 핸들 모음
나 자신이 더 편안하게 찾을 때문에, CommonJS에게 모듈 정의 스타일을 다음 해요 :
define(function(require) {
var Backbone = require('Backbone')
var Item = require('model/item')
// ...
})
그리고 이것은 내 requirejs의 설정입니다 :
require.config({
baseUrl: "/javascripts/",
paths: {
jquery: 'components/jquery/jquery',
underscore: 'components/underscore/underscore',
backbone: 'components/backbone/backbone',
handlebars: 'components/handlebars/handlebars',
text: 'components/text/text'
},
shim: {
underscore: {
exports: "_"
},
handlebars : {
exports: "Handlebars"
},
backbone: {
deps: ['underscore', 'jquery'],
exports: 'Backbone'
}
}
});
모든 전에 부드러운 실행 최적화, 문제가 발생하지 않습니다.
하지만 r.js 종속성을 사용한 최적화가 중단 된 것 같습니다. 내가 브라우저에서 최적화 된 자바 스크립트를 실행할 때, 내가 할 모든 jQuery를하고 핸들 바는 저 말, 오류 메시지입니다 지금
({
baseUrl: ".",
paths: {
jquery: "components/jquery/jquery",
underscore: "components/underscore/underscore",
handlebars: "components/handlebars/handlebars",
backbone: "components/backbone/backbone",
text: "components/text/text"
},
// we use almond minimal amd module loader
name: "components/almond/almond",
// the application entry point
include: ['app/init'],
// we need to teel almond to require app/init
insertRequire: ['app/init'],
out: "main.js",
cjsTranslate: true,
wrap: true,
optimize: "none"
})
: 나는 아몬드 JS 생산을 사용하고 싶습니다, 그래서 여기 내 빌드 파일입니다 정의되지 않음 (물론 Backbone.$
은 아닙니다).
간단한 해결 방법은 jQuery를 로딩을 강제로, 그리고 다음과 같이 백본에 할당 :
var $ = require('jQuery')
var Backbone = require('Backbone')
Backbone.$ = $
을하지만 그것은 나에게 매우 어리석은 중복 소리가 난다. 내가 뭔가 잘못하고있는 것 같지만 무엇을 알아 내지 못합니다.
최적화 후 핸들 바가 종속성으로로드되지 않습니다. 강제로로드하면 (jQuery와 마찬가지로) 빌드 프로세스 중에 fs
(npm 패키지) 모듈을 찾을 수 없다는 오류 메시지가 나타납니다.
Google 검색에서 제안 된 솔루션이 전혀 작동하지 않더라도 내 문제와 관련이있는 것으로 보이는 Google 그룹 (https://groups.google.com/forum/?fromgroups=#!topic/requirejs/lYwXS-3qjXg)에서만이 주제가 발견되었습니다.
여기 백본과 함께 require.js를 사용하는 간단한 자습서를 읽을 수 있습니다. http://addyosmani.github.com/backbone-fundamentals/#modular-development –
도움을 주셔서 감사합니다. 이미 Addy의 튜토리얼을 보았습니다. 그러나 나에게는 잘못된 것을하고있는 것처럼 보입니다. 나는 그것을 더 자세히 보게된다. –