저는 RequireJS를 처음 사용하고로드 순서가 고착되었습니다.RequireJs로 특정 순서로 파일로드
js/app/*에있는 모듈보다 먼저로드해야하는 전역 프로젝트 구성이 있습니다.
다음index.html
config.js
js/
require.js
app/
login.js
lib/
bootstrap-2.0.4.min.js
는 config.js 파일입니다 :
var Project = {
'server': {
'host': '127.0.0.1',
'port': 8080
},
'history': 10, // Number of query kept in the local storage history
'lang': 'en', // For future use
};
그리고 여기 내 requirejs 파일입니다 (app.js) :
requirejs.config({
//By default load any module IDs from js/lib
baseUrl: 'js/lib',
//except, if the module ID starts with "app",
//load it from the js/app directory. paths
//config is relative to the baseUrl, and
//never includes a ".js" extension since
//the paths config could be for a directory.
paths: {
bootstrap: '../lib/bootstrap-2.0.4.min',
app: '../app',
},
shim: {
'app': {
deps: ['../../config'],
exports: function (a) {
console.log ('loaded!');
console.log (a);
}
} // Skual Config
},
});
var modules = [];
modules.push('jquery');
modules.push('bootstrap');
modules.push('app/login');
// Start the main app logic.
requirejs(modules, function ($) {});
그러나 몇 번 여기
내 struture입니다 , 페이지를로드 할 때 login.js가 config.js 전에로드되었으므로 "프로젝트"가 정의되지 않았습니다.config.js를 처음로드 할 때 강제로 어떻게 할 수 있습니까?
참고 : Order.js를 RequireJS의 플러그인으로 보았지만 v2가 shim
으로 바뀌면서 지원되지 않는 것 같습니다.
도움 주셔서 감사합니다.
동의합니다. 개발 과정에서 일시적으로 달성 할 필요가 있었고 충분히 좋았습니다! –
위의 코드를 _requirejs-config.js_에 넣어도 순서대로로드 할 수 있습니다. – Sunry