2014-05-17 26 views
2

我剛開始使用CodeMirror(4.1)並使用RequireJs。 (我也使用ReactJs,但我很確定這不是問題)RequireJS/CodeMirror(sql模式) - 如何使它工作

我明顯沒有正確配置它。如果有人能指出我的錯誤,我將不勝感激。

我的配置是這樣的

require.config({ 

deps: ["main"], 

paths: { 
    ... 
    codemirror:   "../../external/codemirror/codemirror-4.1/lib/codemirror", 
    cmsql:    "../../external/codemirror/codemirror-4.1/mode/sql/sql" 
}, 

shim: { 
    ... 
    codemirror:   { exports: "codemirror" }, 
    cmsql:    { deps: ["codemirror"], exports: "cmsql" }  
} 

});

,我實例化模塊是如下:

define(['jquery', 'react', 'codemirror', 'cmsql'], 
function ($, React, CodeMirror) { 

return React.createClass({ 

    render: function() { 
    console.log("render-editarea"); 
    return (
     <textarea id="editarea"> 
     -- Comment here 
     SELECT ID 
     FROM [Patient Demographics] 
     </textarea> 
    ) 
    }, 

    componentDidMount: function() {     
    var editorNode = document.getElementById("editarea"); 
    var editor = CodeMirror.fromTextArea(editorNode, {   
     lineNumbers: true, 
     matchBrackets: true, 
     indentUnit: 4, 
     mode: "text/x-sql" 
    });   
    }, 

    }); 
}); 

的CodeMirror手冊出現使用模塊裝載機何時顯示此配置。

我可以看到CodeMirror的影響中說行號等方面而不是在語法方面的着色

enter image description here

因此,任何幫助將受到歡迎。

小號

回答

4

爲什麼只要您發佈

答案是(有一次,我消化手動多一點)的東西...是

require.config({ 

    deps: ["main"], 

    paths: { 
    cm:     "../../external/codemirror/codemirror-4.1" 
    }, 

    shim: { 
    ... 
    } 

}); 

define(['jquery', 'react', 'cm/lib/codemirror', 'cm/mode/sql/sql'], 
    function ($, React, CodeMirror) { 
    ... 
0

感謝您的解決方案。它爲我工作。在require中,指向基本CodeMirror目錄,然後參考如上所示。 CodeMirror似乎使用似乎混淆require的相對路徑(它可能是相反的方式)。

相關問題