brace icon indicating copy to clipboard operation
brace copied to clipboard

Loading modes on demand

Open jwheare opened this issue 7 years ago • 2 comments

Vanilla ace manages loading in syntax modes on demand whenever they're set, without having to specify them all up front. Our editor has a drop down to choose syntax from all the available modes and we don't want to include all the modes in our webpack bundle.

Is there a way to do this that doesn't involve something like this?

require('brace/mode/a');
require('brace/mode/b');
...
require('brace/mode/z');

jwheare avatar Dec 15 '17 18:12 jwheare

You could create this logic on your own using import()/require.ensure and then change Ace mode in callback.

// pseudocode solution
select.on('change', () => {
  import('brace/mode/javascript').then(() => editor.getSession().setMode('ace/mode/javascript'))
})

You could get fancy with chunk names etc.

JackuB avatar Jan 17 '18 09:01 JackuB

Thanks, I've tried at various points to get webpack dynamic import working but I can't get my head around it alongside our existing CommonsChunkPlugin setup. I switched back to using vanilla ace outside webpack.

jwheare avatar Jan 17 '18 16:01 jwheare