Using Ace with Require.js

905 views
Skip to first unread message

Tom Dalton

unread,
Jun 11, 2014, 6:20:52 AM6/11/14
to ace-d...@googlegroups.com
Hi,

I originally raised this issue here: https://github.com/ajaxorg/ace-builds/issues/35 before I discovered the google group, but I think this place is more appropriate.

My project is currently using Ace with Require.js. We have the original source tree in a static assest directory and everything is working fine. However, this uncompressed verison of Ace is about 1MB and we want to reduce it. So I found the minified pre-built version here (https://github.com/ajaxorg/ace-builds) and assumed I could use it as a direct replacement. However, that doesn't work - require.js doesnt seem to understnad that various source modules/files are concatenated into ace.js, and additionally it also doesnt seem to like the changes like ace/ext/file.js -> ace/ext-file.js.

Am I on completely the wrong track here? The pre-built packages (src and src-min) both still have the define() and require() calls that makes me think they should still work with require, but for example, the "ace/ace" module requires "ace/lib/fixoldbrowsers". In the source version the module are stored as "ace/ace.js" and "ace/lib/fixoldbrowsers.js", and that works fine with Require. However, in the 'built' versions, both of those modules are concated into ace/ace.js, and Require seems tob e getting confused. I'd assumed it would 'just work' but I'm 90% JS noob and 99% Ace and Require.js noob.

Should I be ignoring the pre-built packages completely and minifying it myself with Require? Should i not be using Require and adding all the <script> includes I need manually?

Any and all help would be gratefully received!

Cheers,

Tom

Harutyun Amirjanyan

unread,
Jun 11, 2014, 5:30:36 PM6/11/14
to ace-d...@googlegroups.com
Hi

require.js not working seems to be a recent regression, if i move the
first define('ace/ace" [] in the src/ace.js to the end it works fine

with the snippet from the issue you created:

require.config({paths: {ace: "../build/src"}})
define('testace', ['ace/ace'], function(ace) {
console.log("This is the testace module");
var editor = ace.edit("editor");
});
require(['testace'])



when build regression fixed, this setup should work well, except for
extensions for which you'd need to use
ext-file instead of ext/file.

but subdirectory-file naming structure is only kept for compatibility
with older versions, and should be changed to saner subdirectory/file
soon

Tom Dalton

unread,
Jun 12, 2014, 4:05:25 AM6/12/14
to ace-d...@googlegroups.com
Ok, that makes me feel a little better (that I'm not going mad)! For anyone else experiencing this in the short term, I fixed it by adding a 'bundles' config item in require.js, effectively mapping all of the (concatenated modules) into the built ace.js file. It's ugly and verbose, but seems to work for now.
Reply all
Reply to author
Forward
0 new messages