Skip to content

Commit

Permalink
feat: Use mini require (#4845)
Browse files Browse the repository at this point in the history
Merge pull request #4845 from ajaxorg/use-mini_require
  • Loading branch information
andrewnester authored Jul 18, 2022
2 parents 922a50e + 30ea87e commit b9fabd4
Show file tree
Hide file tree
Showing 10 changed files with 806 additions and 2,164 deletions.
15 changes: 13 additions & 2 deletions Makefile.dryice.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ function buildAceModuleInternal(opts, callback) {
ignore: opts.ignore || [],
withRequire: false,
basepath: ACE_HOME,
transforms: [normalizeLineEndings],
transforms: [normalizeLineEndings, includeLoader],
afterRead: [optimizeTextModules]
}, write);
}
Expand All @@ -358,7 +358,7 @@ function buildCore(options, extra, callback) {
order: -1000,
literal: true
}];
options.require =["ace/ace"];
options.require =["ace/ace", "ace/loader_build"];
options.projectType = "main";
options.ns = "ace";
buildAceModule(options, callback);
Expand Down Expand Up @@ -583,6 +583,17 @@ function normalizeLineEndings(module) {
return module.source = module.source.replace(/\r\n/g, "\n");
}

function includeLoader(module) {
var pattern = '"include loader_build";';
if (module.source && module.source.indexOf(pattern) != -1) {
console.log("===================================== =====================================");
console.log(module);
console.log("===================================== =====================================");
module.deps.push("ace/loader_build");
module.source = module.source.replace(pattern, 'require("./loader_build")(exports)');
}
}

function optimizeTextModules(sources) {
var textModules = {};
return sources.filter(function(pkg) {
Expand Down
9 changes: 6 additions & 3 deletions demo/kitchen-sink/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
define(function(require, exports, module) {
"use strict";

require("ace/lib/fixoldbrowsers");

require("ace/ext/rtl");

require("ace/multi_select");
Expand All @@ -42,7 +40,12 @@ var devUtil = require("./dev_util");
require("./file_drop");

var config = require("ace/config");
config.init();
config.setLoader(function(moduleName, cb) {
require([moduleName], function(module) {
cb(null, module)
})
});

var env = {};

var dom = require("ace/lib/dom");
Expand Down
3 changes: 2 additions & 1 deletion demo/kitchen-sink/dev_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* ***** END LICENSE BLOCK ***** */

define(function(require, exports, module) {
var ace = require("ace/ace");
var dom = require("ace/lib/dom");
var event = require("ace/lib/event");
var Range = require("ace/range").Range;
Expand All @@ -48,7 +49,7 @@ function def(o, key, get) {
console.error(e);
}
}
def(window, "ace", function(){ return window.env.editor });
def(window, "ace", function(){ return ace });
def(window, "editor", function(){ return window.env.editor == logEditor ? editor : window.env.editor });
def(window, "session", function(){ return window.editor.session });
def(window, "split", function(){ return window.env.split });
Expand Down
Loading

0 comments on commit b9fabd4

Please sign in to comment.