安装了bower的ACE编辑器找不到我的模式

时间:2016-04-25 07:30:40

标签: javascript requirejs bower amd ace-editor

我为ACE editor

编写了自定义模式

我-mode.js

ace.define('my-mode', [/* ... */], function(require, exports, module) { /* ... */ });

我尝试使用

index.js

var editor = ace.edit('editor');
editor.getSession().setMode('my-mode');

我用凉亭安装了ACE编辑器( ace-builds )和 requirejs

bower.json

{
  "name": "my-project",
  "dependencies": {
    "ace-builds": "^1.2.3",
    "requirejs": "^2.2.0"
  }
}

并配置 requirejs

requirejs-config.js

require.config({
  paths: {
    ace: "bower_components/ace-builds/src-noconflict/ace"
  }
});

我的页面看起来像这样

的index.html

<body>
  <div id="editor"></div>

  <script src="bower_components/requirejs/require.js"></script>
  <script src="requirejs-config.js"></script>
  <script src="bower_components/ace-builds/src-noconflict/ace.js"></script>
  <script src="my-mode.js"></script>
  <script src="index.js"></script>
</body>

可悲的是,电话

editor.getSession().setMode('my-mode');

导致错误

Failed to load resource: http://localhost:5555/bower_components/ace-builds/src-noconflict/mode-my-mode.js
the server responded with a status of 404 (Not Found)

如何配置 ace requirejs 以便找到 my-mode

1 个答案:

答案 0 :(得分:0)

I found a solution. Before my-mode is used (for example at the beginning of index.js) call

ace.config.setModuleUrl('my-mode', '/path/to/my-mode.js');