本地&sdk&gh-pages改成min版本的 monaco-editor

This commit is contained in:
2betop 2020-07-20 18:03:10 +08:00
parent 50aa27dba7
commit 47d2bc7bd1
7 changed files with 588 additions and 618 deletions

View File

@ -132,11 +132,13 @@ module.exports = function (ret, pack, settings, opt) {
} catch (e) { } catch (e) {
d = (/((?:https?|file)\:.*)$/.test(e.stack) && RegExp.$1).replace(/\\/[^\\/]*$/, ''); d = (/((?:https?|file)\:.*)$/.test(e.stack) && RegExp.$1).replace(/\\/[^\\/]*$/, '');
} }
${contents ${contents.replace(/\"url\"\s*\:\s*('|")(\.\/.*)\1/g, function (
.replace(/\"url\"\s*\:\s*('|")(\.\/.*)\1/g, function (_, quote, value) { _,
quote,
value
) {
return `"url": d + ${quote}${value.substring(1)}${quote}`; return `"url": d + ${quote}${value.substring(1)}${quote}`;
}) })}
.replace(/require\.resourceMap/, 'amis.require.resourceMap')}
})()`; })()`;
} }

View File

@ -62,7 +62,7 @@
})(); })();
/* @require ./index.jsx 标记为同步依赖,提前加载 */ /* @require ./index.jsx 标记为同步依赖,提前加载 */
require(['./index.jsx'], function (app) { amis.require(['./index.jsx'], function (app) {
var initialState = {}; var initialState = {};
app.bootstrap(document.getElementById('root'), initialState); app.bootstrap(document.getElementById('root'), initialState);
}); });

View File

@ -0,0 +1,235 @@
// 这是个特殊的方法,请看考 mod.js 里面的实现。
export function __mod__async__load(callback: (exports: any) => void) {
// @ts-ignore
const monacoLoader = __uri('monaco-editor/min/vs/loader.js');
// @ts-ignore
const script = amis.require.loadJs(filterUrl(monacoLoader));
script.onload = () => onLoad(window.require, callback);
}
function __uri(url: string) {
return url;
}
// 用于发布 sdk 版本的时候替换,因为不确定 sdk 版本怎么部署,而 worker 地址路径不可知。
// 所以会被 fis3 替换成取相对的代码。
function filterUrl(url: string) {
return url;
}
function onLoad(req: any, callback: (result: any) => void) {
const config = {
'vs/nls': {
availableLanguages: {
'*': 'zh-cn'
}
},
'paths': {
'vs': __uri('monaco-editor/min/vs/editor/editor.main.js').replace(
/\/vs\/.*$/,
''
),
'vs/base/worker/workerMain': __uri(
'monaco-editor/min/vs/base/worker/workerMain.js'
),
'vs/basic-languages/apex/apex': __uri(
'monaco-editor/min/vs/basic-languages/apex/apex'
),
'vs/basic-languages/azcli/azcli': __uri(
'monaco-editor/min/vs/basic-languages/azcli/azcli'
),
'vs/basic-languages/clojure/clojure': __uri(
'monaco-editor/min/vs/basic-languages/clojure/clojure'
),
'vs/basic-languages/bat/bat': __uri(
'monaco-editor/min/vs/basic-languages/bat/bat'
),
'vs/basic-languages/coffee/coffee': __uri(
'monaco-editor/min/vs/basic-languages/coffee/coffee'
),
'vs/basic-languages/cpp/cpp': __uri(
'monaco-editor/min/vs/basic-languages/cpp/cpp'
),
'vs/basic-languages/csharp/csharp': __uri(
'monaco-editor/min/vs/basic-languages/csharp/csharp'
),
'vs/basic-languages/css/css': __uri(
'monaco-editor/min/vs/basic-languages/css/css'
),
'vs/basic-languages/dockerfile/dockerfile': __uri(
'monaco-editor/min/vs/basic-languages/dockerfile/dockerfile'
),
'vs/basic-languages/fsharp/fsharp': __uri(
'monaco-editor/min/vs/basic-languages/fsharp/fsharp'
),
'vs/basic-languages/go/go': __uri(
'monaco-editor/min/vs/basic-languages/go/go'
),
'vs/basic-languages/handlebars/handlebars': __uri(
'monaco-editor/min/vs/basic-languages/handlebars/handlebars'
),
'vs/basic-languages/html/html': __uri(
'monaco-editor/min/vs/basic-languages/html/html'
),
'vs/basic-languages/ini/ini': __uri(
'monaco-editor/min/vs/basic-languages/ini/ini'
),
'vs/basic-languages/java/java': __uri(
'monaco-editor/min/vs/basic-languages/java/java'
),
'vs/basic-languages/javascript/javascript': __uri(
'monaco-editor/min/vs/basic-languages/javascript/javascript'
),
'vs/basic-languages/less/less': __uri(
'monaco-editor/min/vs/basic-languages/less/less'
),
'vs/basic-languages/lua/lua': __uri(
'monaco-editor/min/vs/basic-languages/lua/lua'
),
'vs/basic-languages/markdown/markdown': __uri(
'monaco-editor/min/vs/basic-languages/markdown/markdown'
),
'vs/basic-languages/msdax/msdax': __uri(
'monaco-editor/min/vs/basic-languages/msdax/msdax'
),
'vs/basic-languages/objective-c/objective-c': __uri(
'monaco-editor/min/vs/basic-languages/objective-c/objective-c'
),
'vs/basic-languages/php/php': __uri(
'monaco-editor/min/vs/basic-languages/php/php'
),
'vs/basic-languages/postiats/postiats': __uri(
'monaco-editor/min/vs/basic-languages/postiats/postiats'
),
'vs/basic-languages/powershell/powershell': __uri(
'monaco-editor/min/vs/basic-languages/powershell/powershell'
),
'vs/basic-languages/pug/pug': __uri(
'monaco-editor/min/vs/basic-languages/pug/pug'
),
'vs/basic-languages/python/python': __uri(
'monaco-editor/min/vs/basic-languages/python/python'
),
'vs/basic-languages/r/r': __uri(
'monaco-editor/min/vs/basic-languages/r/r'
),
'vs/basic-languages/razor/razor': __uri(
'monaco-editor/min/vs/basic-languages/razor/razor'
),
'vs/basic-languages/redis/redis': __uri(
'monaco-editor/min/vs/basic-languages/redis/redis'
),
'vs/basic-languages/redshift/redshift': __uri(
'monaco-editor/min/vs/basic-languages/redshift/redshift'
),
'vs/basic-languages/ruby/ruby': __uri(
'monaco-editor/min/vs/basic-languages/ruby/ruby'
),
'vs/basic-languages/rust/rust': __uri(
'monaco-editor/min/vs/basic-languages/rust/rust'
),
'vs/basic-languages/sb/sb': __uri(
'monaco-editor/min/vs/basic-languages/sb/sb'
),
'vs/basic-languages/scheme/scheme': __uri(
'monaco-editor/min/vs/basic-languages/scheme/scheme'
),
'vs/basic-languages/scss/scss': __uri(
'monaco-editor/min/vs/basic-languages/scss/scss'
),
'vs/basic-languages/shell/shell': __uri(
'monaco-editor/min/vs/basic-languages/shell/shell'
),
'vs/basic-languages/solidity/solidity': __uri(
'monaco-editor/min/vs/basic-languages/solidity/solidity'
),
'vs/basic-languages/sql/sql': __uri(
'monaco-editor/min/vs/basic-languages/sql/sql'
),
'vs/basic-languages/st/st': __uri(
'monaco-editor/min/vs/basic-languages/st/st'
),
'vs/basic-languages/swift/swift': __uri(
'monaco-editor/min/vs/basic-languages/swift/swift'
),
'vs/basic-languages/typescript/typescript': __uri(
'monaco-editor/min/vs/basic-languages/typescript/typescript'
),
'vs/basic-languages/vb/vb': __uri(
'monaco-editor/min/vs/basic-languages/vb/vb'
),
'vs/basic-languages/xml/xml': __uri(
'monaco-editor/min/vs/basic-languages/xml/xml'
),
'vs/basic-languages/yaml/yaml': __uri(
'monaco-editor/min/vs/basic-languages/yaml/yaml'
),
'vs/editor/editor.main': __uri(
'monaco-editor/min/vs/editor/editor.main.js'
),
'vs/editor/editor.main.css': __uri(
'monaco-editor/min/vs/editor/editor.main.css'
),
'vs/editor/editor.main.nls': __uri(
'monaco-editor/min/vs/editor/editor.main.nls.js'
),
'vs/editor/editor.main.nls.zh-cn': __uri(
'monaco-editor/min/vs/editor/editor.main.nls.zh-cn.js'
),
// 'vs/editor/contrib/suggest/media/String_16x.svg': __uri('monaco-editor/min/vs/editor/contrib/suggest/media/String_16x.svg'),
// 'vs/editor/contrib/suggest/media/String_inverse_16x.svg': __uri('monaco-editor/min/vs/editor/contrib/suggest/media/String_inverse_16x.svg'),
// 'vs/editor/standalone/browser/quickOpen/symbol-sprite.svg': __uri('monaco-editor/min/vs/editor/standalone/browser/quickOpen/symbol-sprite.svg'),
'vs/language/typescript/tsMode': __uri(
'monaco-editor/min/vs/language/typescript/tsMode.js'
),
// 'vs/language/typescript/lib/typescriptServices': __uri('monaco-editor/min/vs/language/typescript/lib/typescriptServices.js'),
'vs/language/typescript/tsWorker': __uri(
'monaco-editor/min/vs/language/typescript/tsWorker.js'
),
'vs/language/json/jsonMode': __uri(
'monaco-editor/min/vs/language/json/jsonMode.js'
),
'vs/language/json/jsonWorker': __uri(
'monaco-editor/min/vs/language/json/jsonWorker.js'
),
'vs/language/html/htmlMode': __uri(
'monaco-editor/min/vs/language/html/htmlMode.js'
),
'vs/language/html/htmlWorker': __uri(
'monaco-editor/min/vs/language/html/htmlWorker.js'
),
'vs/language/css/cssMode': __uri(
'monaco-editor/min/vs/language/css/cssMode.js'
),
'vs/language/css/cssWorker': __uri(
'monaco-editor/min/vs/language/css/cssWorker.js'
)
}
};
Object.keys(config.paths).forEach((key: keyof typeof config.paths) => {
config.paths[key] = filterUrl(config.paths[key].replace(/\.js$/, ''));
});
req.config(config);
if (/^(https?:)?\/\//.test(config.paths.vs)) {
(window as any).MonacoEnvironment = {
getWorkerUrl: function () {
return `data:text/javascript;charset=utf-8,${encodeURIComponent(`
self.MonacoEnvironment = {
baseUrl: '${config.paths.vs}',
paths: ${JSON.stringify(config.paths)}
};
importScripts('${__uri(
'monaco-editor/min/vs/base/worker/workerMain.js'
)}');`)}`;
}
};
} else {
delete (window as any).MonacoEnvironment;
}
req(['vs/editor/editor.main'], function (ret: any) {
callback(ret);
});
}

View File

@ -1,19 +1,13 @@
/** /**
* @file: mod.js * @file 模块加载器改成私有化的了慎用
* @author fis
* ver: 1.0.13
* update: 2016/01/27
* https://github.com/fex-team/mod
*/ */
var require; /* eslint-disable */
/* eslint-disable no-unused-vars */
var define;
(function (global) { (function (global) {
var require, define;
var amis = window.amis || {};
// 避免重复加载而导致已定义模块丢失 // 避免重复加载而导致已定义模块丢失
if (require) { if (amis.require) {
return; return;
} }
@ -26,7 +20,6 @@ var define;
var pkgMap = {}; var pkgMap = {};
var createScripts = function (queues, onerror) { var createScripts = function (queues, onerror) {
var docFrag = document.createDocumentFragment(); var docFrag = document.createDocumentFragment();
for (var i = 0, len = queues.length; i < len; i++) { for (var i = 0, len = queues.length; i < len; i++) {
@ -57,10 +50,12 @@ var define;
if ('onload' in script) { if ('onload' in script) {
script.onload = onload; script.onload = onload;
} } else {
else {
script.onreadystatechange = function () { script.onreadystatechange = function () {
if (this.readyState === 'loaded' || this.readyState === 'complete') { if (
this.readyState === 'loaded' ||
this.readyState === 'complete'
) {
onload(); onload();
} }
}; };
@ -92,8 +87,7 @@ var define;
if (pkg) { if (pkg) {
url = pkgMap[pkg].url || pkgMap[pkg].uri; url = pkgMap[pkg].url || pkgMap[pkg].uri;
} } else {
else {
url = res.url || res.uri || id; url = res.url || res.uri || id;
} }
@ -106,10 +100,7 @@ var define;
createScripts(queues, onerror); createScripts(queues, onerror);
}; };
define = function (id, factory) { var runQueue = function (id) {
id = id.replace(/\.js$/i, '');
factoryMap[id] = factory;
var queue = loadingMap[id]; var queue = loadingMap[id];
if (queue) { if (queue) {
for (var i = 0, n = queue.length; i < n; i++) { for (var i = 0, n = queue.length; i < n; i++) {
@ -119,8 +110,46 @@ var define;
} }
}; };
require = function (id) { define = function (id, factory) {
id = id.replace(/\.js$/i, '');
factoryMap[id] = factory;
if (~factory.toString().indexOf('__mod__async__load')) {
var mod = {exports: {}};
factoryMap[id] = {
deffer: true,
callbacks: [],
loaded: false,
load: function () {}
};
factory.apply(mod, [require, mod.exports, mod]);
var load = mod.exports.__mod__async__load;
factoryMap[id].load = function () {
if (this.loaded) {
return;
}
this.loaded = true;
load(function (ret) {
var callbacks = factoryMap[id].callbacks;
factoryMap[id] = function () {
return ret;
};
callbacks.forEach(function (fn) {
fn();
});
runQueue(id);
});
};
if (loadingMap[id] && loadingMap[id].length) {
factoryMap[id].load();
}
} else {
runQueue(id);
}
};
require = function (id) {
// compatible with require([dep, dep2...]) syntax. // compatible with require([dep, dep2...]) syntax.
if (id && id.splice) { if (id && id.splice) {
return require.async.apply(this, arguments); return require.async.apply(this, arguments);
@ -148,7 +177,10 @@ var define;
// //
// factory: function OR value // factory: function OR value
// //
var ret = (typeof factory === 'function') ? factory.apply(mod, [require, mod.exports, mod]) : factory; var ret =
typeof factory === 'function'
? factory.apply(mod, [require, mod.exports, mod])
: factory;
if (ret) { if (ret) {
mod.exports = ret; mod.exports = ret;
@ -182,6 +214,12 @@ var define;
needMap[dep] = true; needMap[dep] = true;
if (dep in factoryMap) { if (dep in factoryMap) {
if (factoryMap[dep] && factoryMap[dep].deffer) {
needNum++;
factoryMap[dep].callbacks.push(updateNeed);
factoryMap[dep].load();
}
// check whether loaded resource's deps is loaded or not // check whether loaded resource's deps is loaded or not
child = resMap[dep] || resMap[dep + '.js']; child = resMap[dep] || resMap[dep + '.js'];
if (child && 'deps' in child) { if (child && 'deps' in child) {
@ -253,35 +291,17 @@ var define;
script.type = 'text/javascript'; script.type = 'text/javascript';
script.src = url; script.src = url;
head.appendChild(script); head.appendChild(script);
return script;
}; };
require.loadCss = function (cfg) {
if (cfg.content) {
var sty = document.createElement('style');
sty.type = 'text/css';
if (sty.styleSheet) { // IE
sty.styleSheet.cssText = cfg.content;
}
else {
sty.innerHTML = cfg.content;
}
head.appendChild(sty);
}
else if (cfg.url) {
var link = document.createElement('link');
link.href = cfg.url;
link.rel = 'stylesheet';
link.type = 'text/css';
head.appendChild(link);
}
};
require.alias = function (id) { require.alias = function (id) {
return id.replace(/\.js$/i, ''); return id.replace(/\.js$/i, '');
}; };
require.timeout = 5000; require.timeout = 5000;
amis.require = require;
amis.define = define;
window.amis = amis;
// window.require = window.require || require;
})(this); })(this);

View File

@ -1,265 +0,0 @@
/**
* @file mod-sandbox.js.
*/
/* eslint-disable */
(function (global) {
var require, define;
var amis = window.amis || {};
// 避免重复加载而导致已定义模块丢失
if (amis.require) {
return;
}
var head = document.getElementsByTagName('head')[0];
var loadingMap = {};
var factoryMap = {};
var modulesMap = {};
var scriptsMap = {};
var resMap = {};
var pkgMap = {};
var createScripts = function (queues, onerror) {
var docFrag = document.createDocumentFragment();
for (var i = 0, len = queues.length; i < len; i++) {
var id = queues[i].id;
var url = queues[i].url;
if (url in scriptsMap) {
continue;
}
scriptsMap[url] = true;
var script = document.createElement('script');
if (onerror) {
(function (script, id) {
var tid = setTimeout(function () {
onerror(id);
}, require.timeout);
script.onerror = function () {
clearTimeout(tid);
onerror(id);
};
var onload = function () {
clearTimeout(tid);
};
if ('onload' in script) {
script.onload = onload;
} else {
script.onreadystatechange = function () {
if (
this.readyState === 'loaded' ||
this.readyState === 'complete'
) {
onload();
}
};
}
})(script, id);
}
script.type = 'text/javascript';
script.src = url;
docFrag.appendChild(script);
}
head.appendChild(docFrag);
};
var loadScripts = function (ids, callback, onerror) {
var queues = [];
for (var i = 0, len = ids.length; i < len; i++) {
var id = ids[i];
var queue = loadingMap[id] || (loadingMap[id] = []);
queue.push(callback);
//
// resource map query
//
var res = resMap[id] || resMap[id + '.js'] || {};
var pkg = res.pkg;
var url;
if (pkg) {
url = pkgMap[pkg].url || pkgMap[pkg].uri;
} else {
url = res.url || res.uri || id;
}
queues.push({
id: id,
url: url
});
}
createScripts(queues, onerror);
};
define = function (id, factory) {
id = id.replace(/\.js$/i, '');
factoryMap[id] = factory;
var queue = loadingMap[id];
if (queue) {
for (var i = 0, n = queue.length; i < n; i++) {
queue[i]();
}
delete loadingMap[id];
}
};
require = function (id) {
// compatible with require([dep, dep2...]) syntax.
if (id && id.splice) {
return require.async.apply(this, arguments);
}
id = require.alias(id);
var mod = modulesMap[id];
if (mod) {
return mod.exports;
}
//
// init module
//
var factory = factoryMap[id];
if (!factory) {
throw '[ModJS] Cannot find module `' + id + '`';
}
mod = modulesMap[id] = {
exports: {}
};
//
// factory: function OR value
//
var ret =
typeof factory === 'function'
? factory.apply(mod, [require, mod.exports, mod])
: factory;
if (ret) {
mod.exports = ret;
}
return mod.exports;
};
require.async = function (names, onload, onerror) {
if (typeof names === 'string') {
names = [names];
}
var needMap = {};
var needNum = 0;
var needLoad = [];
function findNeed(depArr) {
var child;
for (var i = 0, n = depArr.length; i < n; i++) {
//
// skip loading or loaded
//
var dep = require.alias(depArr[i]);
if (dep in needMap) {
continue;
}
needMap[dep] = true;
if (dep in factoryMap) {
// check whether loaded resource's deps is loaded or not
child = resMap[dep] || resMap[dep + '.js'];
if (child && 'deps' in child) {
findNeed(child.deps);
}
continue;
}
needLoad.push(dep);
needNum++;
child = resMap[dep] || resMap[dep + '.js'];
if (child && 'deps' in child) {
findNeed(child.deps);
}
}
}
function updateNeed() {
if (0 === needNum--) {
var args = [];
for (var i = 0, n = names.length; i < n; i++) {
args[i] = require(names[i]);
}
onload && onload.apply(global, args);
}
}
findNeed(names);
loadScripts(needLoad, updateNeed, onerror);
updateNeed();
};
require.ensure = function (names, callback) {
require.async(names, function () {
callback && callback.call(this, require);
});
};
require.resourceMap = function (obj) {
var k;
var col;
// merge `res` & `pkg` fields
col = obj.res;
for (k in col) {
if (col.hasOwnProperty(k)) {
resMap[k] = col[k];
}
}
col = obj.pkg;
for (k in col) {
if (col.hasOwnProperty(k)) {
pkgMap[k] = col[k];
}
}
};
require.loadJs = function (url) {
if (url in scriptsMap) {
return;
}
scriptsMap[url] = true;
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
head.appendChild(script);
};
require.alias = function (id) {
return id.replace(/\.js$/i, '');
};
require.timeout = 5000;
amis.require = require;
amis.define = define;
window.amis = amis;
// window.require = window.require || require;
})(this);

View File

@ -10,7 +10,7 @@
<!--STYLE_PLACEHOLDER--> <!--STYLE_PLACEHOLDER-->
</head> </head>
<body> <body>
<script data-loader src="./sdk-mod.js"></script> <script data-loader src="./mod.js"></script>
<script> <script>
/* @require "./embed.tsx" */ /* @require "./embed.tsx" */
/* @require "./loader" */ /* @require "./loader" */

View File

@ -8,6 +8,27 @@ const parserMarkdown = require('./build/md-parser');
fis.get('project.ignore').push('public/**', 'gh-pages/**', '.*/**'); fis.get('project.ignore').push('public/**', 'gh-pages/**', '.*/**');
// 配置只编译哪些文件。 // 配置只编译哪些文件。
const Resource = fis.require('postpackager-loader/lib/resource.js');
Resource.extend({
buildResourceMap: function () {
return 'amis.' + this.__super();
},
calculate: function () {
this.__super.apply(this);
// 标记这个文件,肯定是异步资源,即便是同步加载了。
Object.keys(this.loaded).forEach(id => {
const file = this.getFileById(id);
if (file && file.subpath === '/examples/loadMonacoEditor.ts') {
this.loaded[id] = true;
}
});
}
});
fis.set('project.files', [ fis.set('project.files', [
'scss/**.scss', 'scss/**.scss',
'/examples/*.html', '/examples/*.html',
@ -69,6 +90,15 @@ fis.match('tinymce/plugins/*/index.js', {
ignoreDependencies: false ignoreDependencies: false
}); });
fis.match(/(?:flv\.js)/, {
ignoreDependencies: true
});
fis.match('monaco-editor/min/**.js', {
isMod: false,
ignoreDependencies: true
});
fis.match('/docs/**.md', { fis.match('/docs/**.md', {
rExt: 'js', rExt: 'js',
parser: [ parser: [
@ -103,14 +133,24 @@ fis.on('compile:parser', function (file) {
} }
}); });
fis.match('monaco-editor/esm/**.js', { fis.on('compile:optimizer', function (file) {
parser: fis.plugin('typescript', { if (file.isJsLike && file.isMod) {
importHelpers: true, var contents = file.getContent();
esModuleInterop: true,
experimentalDecorators: true, if (
sourceMap: false typeof contents === 'string' &&
}), contents.substring(0, 7) === 'define('
preprocessor: fis.plugin('js-require-css') ) {
contents = 'amis.' + contents;
contents = contents.replace(
'function(require, exports, module)',
'function(require, exports, module, define)'
);
file.setContent(contents);
}
}
}); });
fis.match('{*.ts,*.jsx,*.tsx,/src/**.js,/src/**.ts}', { fis.match('{*.ts,*.jsx,*.tsx,/src/**.js,/src/**.ts}', {
@ -145,22 +185,14 @@ fis.hook('node_modules', {
// shutup: true // shutup: true
}); });
fis.hook('commonjs', { fis.hook('commonjs', {
extList: ['.js', '.jsx', '.tsx', '.ts'] sourceMap: false,
extList: ['.js', '.jsx', '.tsx', '.ts'],
paths: {
'monaco-editor': '/examples/loadMonacoEditor'
}
}); });
fis.media('dev').match('::package', { fis.media('dev').match('::package', {
prepackager: fis.plugin('stand-alone-pack', {
'/pkg/editor.worker.js': 'monaco-editor/esm/vs/editor/editor.worker.js',
'/pkg/json.worker.js': 'monaco-editor/esm/vs/language/json/json.worker',
'/pkg/css.worker.js': 'monaco-editor/esm/vs/language/css/css.worker',
'/pkg/html.worker.js': 'monaco-editor/esm/vs/language/html/html.worker',
'/pkg/ts.worker.js': 'monaco-editor/esm/vs/language/typescript/ts.worker',
// 替换这些文件里面的路径引用。
// 如果不配置,源码中对于打包文件的引用是不正确的。
'replaceFiles': ['src/components/Editor.tsx']
}),
postpackager: fis.plugin('loader', { postpackager: fis.plugin('loader', {
useInlineMap: false, useInlineMap: false,
resourceType: 'mod' resourceType: 'mod'
@ -171,6 +203,10 @@ fis.media('dev').match('/node_modules/**.js', {
packTo: '/pkg/npm.js' packTo: '/pkg/npm.js'
}); });
fis.match('monaco-editor/**', {
packTo: null
});
if (fis.project.currentMedia() === 'publish') { if (fis.project.currentMedia() === 'publish') {
const publishEnv = fis.media('publish'); const publishEnv = fis.media('publish');
publishEnv.get('project.ignore').push('lib/**'); publishEnv.get('project.ignore').push('lib/**');
@ -333,10 +369,10 @@ if (fis.project.currentMedia() === 'publish') {
env.match('::package', { env.match('::package', {
packager: fis.plugin('deps-pack', { packager: fis.plugin('deps-pack', {
'sdk.js': [ 'sdk.js': [
'examples/sdk-mod.js', 'examples/mod.js',
'examples/embed.tsx', 'examples/embed.tsx',
'examples/embed.tsx:deps', 'examples/embed.tsx:deps',
'!monaco-editor/**', 'examples/loadMonacoEditor.ts',
'!flv.js/**', '!flv.js/**',
'!hls.js/**', '!hls.js/**',
'!froala-editor/**', '!froala-editor/**',
@ -344,7 +380,8 @@ if (fis.project.currentMedia() === 'publish') {
'!jquery/**', '!jquery/**',
'!zrender/**', '!zrender/**',
'!echarts/**', '!echarts/**',
'!docsearch.js/**' '!docsearch.js/**',
'!monaco-editor/**.css'
], ],
'rich-text.js': [ 'rich-text.js': [
@ -357,11 +394,6 @@ if (fis.project.currentMedia() === 'publish') {
'charts.js': ['zrender/**', 'echarts/**'], 'charts.js': ['zrender/**', 'echarts/**'],
'editor.js': [
'monaco-editor/esm/vs/editor/editor.main.js',
'monaco-editor/esm/vs/editor/editor.main.js:deps'
],
'rest.js': [ 'rest.js': [
'*.js', '*.js',
'!monaco-editor/**', '!monaco-editor/**',
@ -384,13 +416,20 @@ if (fis.project.currentMedia() === 'publish') {
] ]
}); });
env.match('{*.min.js,monaco-editor/min/**.js}', {
optimizer: null
});
fis.on('compile:optimizer', function (file) { fis.on('compile:optimizer', function (file) {
if (file.isJsLike && file.isMod) { if (file.isJsLike && file.isMod) {
var contents = file.getContent(); var contents = file.getContent();
// 替换 worker 地址的路径,让 sdk 加载同目录下的文件。 // 替换 worker 地址的路径,让 sdk 加载同目录下的文件。
// 如果 sdk 和 worker 不是部署在一个地方,请通过指定 MonacoEnvironment.getWorkerUrl // 如果 sdk 和 worker 不是部署在一个地方,请通过指定 MonacoEnvironment.getWorkerUrl
if (file.subpath === '/src/components/Editor.tsx') { if (
file.subpath === '/src/components/Editor.tsx' ||
file.subpath === '/examples/loadMonacoEditor.ts'
) {
contents = contents.replace( contents = contents.replace(
/function\sfilterUrl\(url\)\s\{\s*return\s*url;/m, /function\sfilterUrl\(url\)\s\{\s*return\s*url;/m,
function () { function () {
@ -404,18 +443,6 @@ if (fis.project.currentMedia() === 'publish') {
return _path + url.substring(1);`; return _path + url.substring(1);`;
} }
); );
}
if (
typeof contents === 'string' &&
contents.substring(0, 7) === 'define('
) {
contents = 'amis.' + contents;
contents = contents.replace(
'function(require, exports, module)',
'function(require, exports, module, define)'
);
file.setContent(contents); file.setContent(contents);
} }
@ -426,40 +453,6 @@ if (fis.project.currentMedia() === 'publish') {
isMod: false isMod: false
}); });
env.match('::packager', {
prepackager: [
fis.plugin('stand-alone-pack', {
'/pkg/editor.worker.js': 'monaco-editor/esm/vs/editor/editor.worker.js',
'/pkg/json.worker.js': 'monaco-editor/esm/vs/language/json/json.worker',
'/pkg/css.worker.js': 'monaco-editor/esm/vs/language/css/css.worker',
'/pkg/html.worker.js': 'monaco-editor/esm/vs/language/html/html.worker',
'/pkg/ts.worker.js':
'monaco-editor/esm/vs/language/typescript/ts.worker',
// 替换这些文件里面的路径引用。
// 如果不配置,源码中对于打包文件的引用是不正确的。
'replaceFiles': ['src/components/Editor.tsx']
}),
function (ret) {
const root = fis.project.getProjectPath();
[
'/pkg/editor.worker.js',
'/pkg/json.worker.js',
'/pkg/css.worker.js',
'/pkg/html.worker.js',
'/pkg/ts.worker.js'
].forEach(function (pkgFile) {
const packedFile = fis.file.wrap(path.join(root, pkgFile));
const file = ret.pkg[packedFile.subpath];
let contents = file.getContent();
contents = contents.replace(/amis\.define/g, 'define');
file.setContent(contents);
});
}
]
});
env.match('*', { env.match('*', {
domain: '.', domain: '.',
deploy: [ deploy: [
@ -559,17 +552,6 @@ if (fis.project.currentMedia() === 'publish') {
}); });
ghPages.match('::package', { ghPages.match('::package', {
prepackager: fis.plugin('stand-alone-pack', {
'/pkg/editor.worker.js': 'monaco-editor/esm/vs/editor/editor.worker.js',
'/pkg/json.worker.js': 'monaco-editor/esm/vs/language/json/json.worker',
'/pkg/css.worker.js': 'monaco-editor/esm/vs/language/css/css.worker',
'/pkg/html.worker.js': 'monaco-editor/esm/vs/language/html/html.worker',
'/pkg/ts.worker.js': 'monaco-editor/esm/vs/language/typescript/ts.worker',
// 替换这些文件里面的路径引用。
// 如果不配置,源码中对于打包文件的引用是不正确的。
'replaceFiles': ['src/components/Editor.tsx']
}),
packager: fis.plugin('deps-pack', { packager: fis.plugin('deps-pack', {
'pkg/npm.js': [ 'pkg/npm.js': [
'/examples/mod.js', '/examples/mod.js',
@ -596,11 +578,6 @@ if (fis.project.currentMedia() === 'publish') {
'/examples/components/App.jsx:deps' '/examples/components/App.jsx:deps'
], ],
'pkg/editor.js': [
'monaco-editor/esm/vs/editor/editor.main.js',
'monaco-editor/esm/vs/editor/editor.main.js:deps'
],
'pkg/rest.js': [ 'pkg/rest.js': [
'**.{js,jsx,ts,tsx}', '**.{js,jsx,ts,tsx}',
'!static/mod.js', '!static/mod.js',
@ -624,6 +601,7 @@ if (fis.project.currentMedia() === 'publish') {
'!/scss/themes/*.scss', '!/scss/themes/*.scss',
// 要切换主题,不能打在一起。'/scss/*.scss', // 要切换主题,不能打在一起。'/scss/*.scss',
'!/examples/style.scss', '!/examples/style.scss',
'!monaco-editor/**',
'/examples/style.scss' // 让它在最下面 '/examples/style.scss' // 让它在最下面
] ]
}), }),
@ -707,7 +685,7 @@ if (fis.project.currentMedia() === 'publish') {
}) })
] ]
}); });
ghPages.match('{*.min.js}', { ghPages.match('{*.min.js,monaco-editor/min/**.js}', {
optimizer: null optimizer: null
}); });
} }