Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load ace editor theme from CDN with requirejs?

I am trying to load an ace theme from a CDN with requirejs.

Here is a plunkr which illustrates my problem. The theme can not be found in the following case:

requirejs.config({
  paths: { ace: ['//cdnjs.cloudflare.com/ajax/libs/ace/1.1.9/'] }
})

$('h1').text("loading ace...");
requirejs([ 'ace/ace'], function(ace) {
  $('h1').text("ace loaded.")
  console.log(ace)
  editor = ace.edit('editor')
  editor.setTheme("ace/theme/monokai")
  return
})

Note: I asked this question to load ace editor with requirejs from CDN, but it does not explain how can I load an ace theme.

like image 376
arthur.sw Avatar asked Jan 09 '23 01:01

arthur.sw


1 Answers

Seems like there is a bug in ace, and one needs to call

ace.config.set("packaged", true)
ace.config.set("basePath", require.toUrl("ace"))

before ace.edit to configure paths.

like image 133
a user Avatar answered Jan 15 '23 09:01

a user