2012-10-31 2 views
8

현재 재미있는 프로젝트를 위해 require.js를 사용하고 있습니다. prism.js라는 코드 구문 하이라이팅 플러그인을 제외한 모든 것이 올바르게 작동하고 있습니다. 플러그인이 네트워크 탭을 통해 Chrome에서 가져 왔지만 플러그인이 초기화되지 않고 있음을 알 수 있습니다.require.js로 비 amd 모듈로드하기

문제가 있거나 플러그인이 문제인지 궁금한 점이 있으시면 도움을받을 수 있는지 궁금합니다.

require.config({ 
    // 3rd party script alias names 
    paths: { 
    // Core Libraries 
    modernizr: "libs/modernizr", 
    jquery: "libs/jquery", 
    underscore: "libs/lodash", 
    backbone: "libs/backbone", 
    handlebars: "libs/handlebars", 

    text: "libs/text", 
    prism: "plugins/prism", 

    templates: "../templates" 
    }, 
    // Sets the configuration for your third party scripts that are not AMD compatible 
    shim: { 
    "backbone": { 
     "deps": ["underscore", "jquery", "handlebars"], 
     "exports": "Backbone" //attaches "Backbone" to the window object 
    } 
    } 
}); 

// Include Specific JavaScript 
require(['prism', 'modernizr', 'jquery', 'backbone', 'routers/router', 'views/AppVIew' ], 
    function(Prism, Modernizr, $, Backbone, Router, App) { 
    this.router = new Router(); 
    this.App = new App(); 
    } 
); 

답변

10

변경 심 섹션은 프리즘을 포함하고 있는지 확인은 "프리즘"수출 :

shim: { 
    "backbone": { 
     "deps": ["underscore", "jquery", "handlebars"], 
     "exports": "Backbone" //attaches "Backbone" to the window object 
    }, 
    "prism": { 
     "exports": "Prism" 
    } 
} 
+0

"shimmed"가되면 어떻게 사용할 수 있습니까? –

+2

다른 모듈과 마찬가지로 :'require ('prism');'또는'define'에 대한 인수에 의존성을 포함시킵니다. –

1

프리즘이 너무 shim에 추가해야합니다 : 여기

내 main.js 살펴입니다. 백본과 마찬가지로 AMD와 호환되지 않으므로 같은 방식으로 선언해야합니다.

+0

도움이 될 것입니다 http://requirejs.org/docs/api.html#config-shim

희망? – Lawrence

+0

예, 제 생각으로는 "플러그인"이라고 부르면 jquery 플러그인을 의미하고 jquery는 depedns로 간주합니다. – yakxxx

3

핸들 바 및 프리즘 AMD (Asyncronous 모듈 정의)과 호환되지 않습니다 그래서 당신은 필요 스스로를 아래처럼;

requirejs.config({ 
    shim: { 
     'backbone': { 
      "deps": ["underscore", "jquery", "handlebars"], 
      "exports": "Backbone" //attaches "Backbone" to the window object 
     }, 
     'handlebars': { 
      "exports": 'Handlebars' 
     }, 
     'prism': { 
      "exports": "Prism" 
     } 
    } 
}); 

require.js shim 문서 사이트를 참조하십시오. 이 플러그인 종속성이없는 경우에도

관련 문제