ui-ace icon indicating copy to clipboard operation
ui-ace copied to clipboard

Theme and mode 404 when using minified/bundled js and workerPath

Open andrewboni opened this issue 9 years ago • 13 comments

I'm using requirejs, as as such, all JS gets concatenated into a single file. I'm setting workerPath to the correct folder containing Ace, but theme and mode don't seem to get picked up. Even specifying paths for both have no effect. screenshot 2015-04-23 00 32 28

Any thoughts on how to correctly get theme and mode working with a requirejs / concatenated / uglified / set up?

Relevant config:

    $scope.uiAceConfig =
      theme: 'chrome'
      mode: 'html'
      onLoad: $scope.aceLoaded
      workerPath: '/public/lib/ace-builds/src-min-noconflict'

Thanks!

andrewboni avatar Apr 23 '15 07:04 andrewboni

+1

cvharris avatar Dec 21 '15 17:12 cvharris

+1

ofirrifo avatar Dec 22 '15 06:12 ofirrifo

+1

charlieargue avatar Jan 13 '16 03:01 charlieargue

I'd say this is a big need for apps inside compiled deployments (crazy, right?). I had to get around this by using the CDN url for the workerPath

<div ui-ace="{
      workerPath: 'https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.2',
      useWrapMode: 'true',
      showGutter: 'true',
      mode: 'json'
    }">

cvharris avatar Jan 13 '16 03:01 cvharris

Is there any other way to solve this ?

Joysond avatar Jan 20 '16 12:01 Joysond

This literally makes ui-ace useless for me.

buildjosh avatar Jan 29 '16 20:01 buildjosh

+1

kevindessely avatar May 12 '16 05:05 kevindessely

Has anyone found a usable workaround?

wilg avatar Jul 12 '16 20:07 wilg

If you place the files where its expecting the files to be present then it might work (you have to copy all the files modes/themes)

Joysond avatar Jul 13 '16 08:07 Joysond

  1. Configure paths to point to ace-builds before concatenation:

For example:

data-ui-ace="{
       ( ... )
       workerPath: 'bower_components/ace-builds/src-min-noconflict',
       modePath: 'bower_components/ace-builds/src-min-noconflict',
       themePath: 'bower_components/ace-builds/src-min-noconflict',
       basePath: 'bower_components/ace-builds/src-min-noconflict'
}"
  1. Make sure you have properly configured bower.json overrides:

For example:

  "overrides": {
    "angular-ui-ace": {
      "main": [
        "../ace-builds/src-min-noconflict/ace.js",
        "../ace-builds/src-min-noconflict/ext-language_tools.js",
        "../ace-builds/src-min-noconflict/worker-css.js",
        "../ace-builds/src-min-noconflict/mode-javascript.js",
        "../ace-builds/src-min-noconflict/theme-monokai.js",
        "../ace-builds/src-min-noconflict/mode-css.js",
        "../ace-builds/src-min-noconflict/mode-html.js",
        ]
}
  1. Replace startWorker function as advised here: https://github.com/ajaxorg/ace/issues/732

CASE 1 You are using "../ace-builds/src-min-noconflict",

To fix the problem place ace.require("ace/edit_session").EditSession.prototype.$startWorker = function(){}

before the function in which you are using ui-ace

CASE 2 You are using "../ace-builds/src",

To fix the problem place
require("ace/edit_session").EditSession.prototype.$startWorker = function(){}

before the function in which you are using ui-ace

for example

(function () {
    'use strict';

    angular
        .module('app.template')
        .controller('TemplateController', TemplateController);

    TemplateController.$inject = [];

    // Quick-fix that allows to omit ACE problem with loading html and css workers
    ace.require("ace/edit_session").EditSession.prototype.$startWorker = function(){};

    // Here you will use ui-ace
    function TemplateController() {
        var vm = this;
    }
})();

lahdo avatar Dec 21 '16 12:12 lahdo

+1

rufengch avatar Jan 20 '17 05:01 rufengch

+1

estwanick avatar Apr 21 '17 02:04 estwanick

I found that I needed to set the properties as @lahdo mentioned:

ui-ace="{
       ...
       workerPath: '/.../ace-builds/src-min-noconflict',
       modePath: '/.../ace-builds/src-min-noconflict',
       themePath: '/.../ace-builds/src-min-noconflict',
       basePath: '/.../ace-builds/src-min-noconflict'
}"

But the ui-ace setOptions() function needs to be modified, too. It's missing the ability to set all of these paths (I'm not sure why it isn't written more generically to do a set on all properties provided that aren't specifically handled in this function):

    var setOptions = function(acee, session, opts) {

      // sets the ace worker path, if running from concatenated
      // or minified source
      if (angular.isDefined(opts.workerPath)) {
        var config = window.ace.require('ace/config');
        config.set('workerPath', opts.workerPath);
      }
      if (angular.isDefined(opts.modePath)) {
        var config = window.ace.require('ace/config');
        config.set('modePath', opts.modePath);
      }
      if (angular.isDefined(opts.themePath)) {
        var config = window.ace.require('ace/config');
        config.set('themePath', opts.themePath);
      }
      if (angular.isDefined(opts.basePath)) {
        var config = window.ace.require('ace/config');
        config.set('basePath', opts.basePath);
      }

cgatesman avatar May 03 '19 13:05 cgatesman