New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using ace-builds with webpack #4782
Comments
For backwards compatibility current version of ace-builds/src does not work with webpack. There is a demo of using ace-builds with webpack at https://github.com/ajaxorg/ace/blob/master/demo/webpack/demo.js, please let me know if you have any questions about it, or have any suggestions on how to improve it. |
This is great help, thank you for taking the time to reply. That sorts out a lot of the dependency errors we were getting from ace, but for custom modes we're still having trouble figuring it out. For example, when using ace without webpack (pure require.js), we would just
However, I can't find, for example, mode/text in the ace-builds repo (or anything about cstyle) Do you have any advice about this? Once we sort this, I will be very happy to get together some suggestions on documentation for using custom modes with webpack. It's possible that my team and I are just missing something obvious, though! EDIT: Maybe we are requiring those modes unecessarily? We would use it in our custom mode definition like:
|
There only a hacky way of doing this for now. use // load the javascript mode which contains cstyle helpers
require("ace-builds/src-noconflict/mode-javascript")
// use ace.require to get internal modules
var CStyleFoldMode = ace.require("ace/mode/folding/cstyle").FoldMode; |
Ok, awesome, will try in a second. For the record, I tried also installing the entire ace-code-editor package alongside ace-builds, and for things like cstyle referring to them inside the ace-code-editor package, and got errors such as
Just to dissuade anybody from going down that route. Will report back about above suggestion in new comment. |
Appreciate the suggestion, this has given us a new avenue to explore. Had forgotten about ace.require (and the acequire equivalent of brace). Unfortunately, we're getting a similar error to above
Just the initial report, still digging to learn more. Thank you for all your help so far, we're getting further now than we have all week. |
For some reason, this error is occuring simply by doing EDIT: It was because I was setting mode to an empty object to debug. |
This error was my fault. The end of our custom mode file looked like
But I was only doing
I should have been doing
Then, later, i did set_mode on
Will comment will full setup momentarily. Thank you for your help @nightwing , I think we've got it sorted! |
For those that come after:
Then you need to do the following in your actual editor code:
|
this is not nessesary import "ace-builds/webpack-resolver";
editor.setTheme('ace/theme/github'); as shown in https://github.com/ajaxorg/ace/blob/master/demo/webpack/demo.js#L12, should work. |
Another option is to leverage a CDN for loading themes / modes. import 'ace-builds/src-min-noconflict/ace' // Load Ace Editor
// Import initial theme and mode so we don't have to wait for 2 extra HTTP requests
import 'ace-builds/src-min-noconflict/theme-chrome'
import 'ace-builds/src-min-noconflict/mode-javascript'
// cdnjs didn't have a "no-conflict" version, so we'll use jsdelivr
const CDN = 'https://cdn.jsdelivr.net/npm/ace-builds@1.3.3/src-min-noconflict';
// Now we tell ace to use the CDN locations to look for files
ace.config.set('basePath', CDN);
ace.config.set('modePath', CDN);
ace.config.set('themePath', CDN);
ace.config.set('workerPath', CDN);
// Create Editor
const editor = ace.edit('editor');
// Set Editor Theme and Mode
editor.setTheme('ace/theme/chrome');
editor.session.setMode('ace/mode/javascript'); Later on you can update the theme / mode, and it'll just fetch the corresponding files from the CDN dynamically. (or you can copy all the files from |
@XanderLuciano Many thanks! This certainly helps! |
You can try this:
|
Bundles a lot of stuff not being used by this example, bloating vendor.js. You could instead import only what you will end-up using. In the example above the following would have been sufficient.
|
|
I used the following code and everything is ok
|
This beats using CDN, because there is a possibility of hosting a project using ace editor that has no internet connection and thus cannot connect to the CDN. |
I use webpack 5.74.0 with ESM modules. Not worked ext-language_tools . Output warnings enableSnippets is reported as misspelled option name This helped me:
|
This relies on |
Please see https://github.com/ajaxorg/ace-samples/tree/master/samples/ace-builds-webpack for a working version of ace-builds with webpack and language-tools For new versions of webpack use |
I'm confused, so what are we supposed to do if we loaded Ace in via cdnjs, and not webpack or other? |
This worked for me. |
We are trying to use ace-builds with webpack.
We have used the line
var Ace = require('ace-builds/src/ace');
We have tried many iterations of "using ace editor with webpack," further documented on the master ace-editor repo.
We worked on this a long time before making an issue in either place, I am doing so now because I have been unable to find a definitive resource on using either ace, ace-builds, or brace with webpack on a repo that uses custom modes.
What is the proper way to use ace-builds with webpack?
The text was updated successfully, but these errors were encountered: