提交 72ef20b5 编写于 作者: A Alex Dima

Improve monaco-editor-core bundling

上级 fa48339a
......@@ -39,13 +39,21 @@ exports.loaderConfig = function (emptyPaths) {
const IS_OUR_COPYRIGHT_REGEXP = /Copyright \(C\) Microsoft Corporation/i;
function loader(bundledFileHeader) {
function loader(bundledFileHeader, bundleLoader) {
let sources = [
'out-build/vs/loader.js'
];
if (bundleLoader) {
sources = sources.concat([
'out-build/vs/css.js',
'out-build/vs/nls.js'
]);
}
let isFirst = true;
return gulp.src([
'out-build/vs/loader.js',
'out-build/vs/css.js',
'out-build/vs/nls.js'
], { base: 'out-build' })
return (
gulp
.src(sources, { base: 'out-build' })
.pipe(es.through(function(data) {
if (isFirst) {
isFirst = false;
......@@ -64,7 +72,8 @@ function loader(bundledFileHeader) {
.pipe(es.mapSync(function (f) {
f.sourceMap.sourceRoot = util.toFileUri(path.join(path.dirname(__dirname), 'src'));
return f;
}));
}))
);
}
function toConcatStream(bundledFileHeader, sources, dest) {
......@@ -116,6 +125,7 @@ function toBundleStream(bundledFileHeader, bundles) {
* - otherSources (for non-AMD files that should get Copyright treatment)
* - resources (svg, etc.)
* - loaderConfig
* - bundleLoader (boolean - true by default - append css and nls to loader)
* - header (basically the Copyright treatment)
* - bundleInfo (boolean - emit bundleInfo.json file)
* - out (out folder name)
......@@ -126,6 +136,7 @@ exports.optimizeTask = function(opts) {
const resources = opts.resources;
const loaderConfig = opts.loaderConfig;
const bundledFileHeader = opts.header;
const bundleLoader = (typeof opts.bundleLoader === 'undefined' ? true : opts.bundleLoader);
const out = opts.out;
return function() {
......@@ -174,7 +185,7 @@ exports.optimizeTask = function(opts) {
}));
const result = es.merge(
loader(bundledFileHeader),
loader(bundledFileHeader, bundleLoader),
bundlesStream,
otherSourcesStream,
resourcesStream,
......
......@@ -22,12 +22,15 @@ var editorEntryPoints = [
{
name: 'vs/editor/editor.main',
include: [],
exclude: [ 'vs/css', 'vs/nls' ]
exclude: [],
prepend: [ 'vs/css.js', 'vs/nls.js' ],
},
{
name: 'vs/base/common/worker/simpleWorker',
include: [ 'vs/editor/common/services/editorSimpleWorker' ],
exclude: [ 'vs/css', 'vs/nls' ]
prepend: [ 'vs/loader.js' ],
append: [ 'vs/base/worker/workerMain' ],
dest: 'vs/base/worker/workerMain.js'
},
]
......@@ -37,14 +40,11 @@ var editorResources = [
'!out-build/vs/base/browser/ui/toolbar/**/*',
'!out-build/vs/base/browser/ui/octiconLabel/**/*',
'!out-build/vs/editor/contrib/defineKeybinding/**/*',
'out-build/vs/base/worker/workerMain.{js,js.map}',
'!out-build/vs/workbench/**',
'!**/test/**'
];
var editorOtherSources = [
'out-build/vs/css.js',
'out-build/vs/nls.js'
];
var BUNDLED_FILE_HEADER = [
......@@ -75,6 +75,7 @@ gulp.task('optimize-editor', ['clean-optimized-editor', 'compile-build'], common
otherSources: editorOtherSources,
resources: editorResources,
loaderConfig: editorLoaderConfig(),
bundleLoader: false,
header: BUNDLED_FILE_HEADER,
bundleInfo: true,
out: 'out-editor'
......
......@@ -31,6 +31,24 @@ function bundle(entryPoints, config, callback) {
var loader = loaderModule.exports;
config.isBuild = true;
loader.config(config);
loader(['require'], function (localRequire) {
var resolvePath = function (path) {
var r = localRequire.toUrl(path);
if (!/\.js/.test(r)) {
return r + '.js';
}
return r;
};
for (var moduleId in entryPointsMap) {
var entryPoint = entryPointsMap[moduleId];
if (entryPoint.append) {
entryPoint.append = entryPoint.append.map(resolvePath);
}
if (entryPoint.prepend) {
entryPoint.prepend = entryPoint.prepend.map(resolvePath);
}
}
});
loader(Object.keys(allMentionedModulesMap), function () {
var modules = loader.getBuildInfo();
var partialResult = emitEntryPoints(modules, entryPointsMap);
......@@ -74,7 +92,7 @@ function emitEntryPoints(modules, entryPoints) {
return allDependencies[module];
});
bundleData.bundles[moduleToBundle] = includedModules;
var res = emitEntryPoint(modulesMap, modulesGraph, moduleToBundle, includedModules);
var res = emitEntryPoint(modulesMap, modulesGraph, moduleToBundle, includedModules, info.prepend, info.append, info.dest);
result = result.concat(res.files);
for (var pluginName in res.usedPlugins) {
usedPlugins[pluginName] = usedPlugins[pluginName] || res.usedPlugins[pluginName];
......@@ -235,10 +253,13 @@ function removeDuplicateTSBoilerplate(destFiles) {
});
return destFiles;
}
function emitEntryPoint(modulesMap, deps, entryPoint, includedModules) {
function emitEntryPoint(modulesMap, deps, entryPoint, includedModules, prepend, append, dest) {
if (!dest) {
dest = entryPoint + '.js';
}
var mainResult = {
sources: [],
dest: entryPoint + '.js'
dest: dest
}, results = [mainResult];
var usedPlugins = {};
var getLoaderPlugin = function (pluginName) {
......@@ -286,6 +307,16 @@ function emitEntryPoint(modulesMap, deps, entryPoint, includedModules) {
plugin.writeFile(pluginName, entryPoint, req, write, {});
}
});
var toIFile = function (path) {
var contents = readFileAndRemoveBOM(path);
return {
path: path,
contents: contents
};
};
var toPrepend = (prepend || []).map(toIFile);
var toAppend = (append || []).map(toIFile);
mainResult.sources = toPrepend.concat(mainResult.sources).concat(toAppend);
return {
files: results,
usedPlugins: usedPlugins
......
......@@ -46,6 +46,9 @@ export interface IEntryPoint {
name: string;
include: string[];
exclude: string[];
prepend: string[];
append: string[];
dest: string;
}
interface IEntryPointMap {
......@@ -120,6 +123,25 @@ export function bundle(entryPoints:IEntryPoint[], config:ILoaderConfig, callback
config.isBuild = true;
loader.config(config);
loader(['require'], (localRequire) => {
let resolvePath = (path:string) => {
let r = localRequire.toUrl(path);
if (!/\.js/.test(r)) {
return r + '.js';
}
return r;
};
for (let moduleId in entryPointsMap) {
let entryPoint = entryPointsMap[moduleId];
if (entryPoint.append) {
entryPoint.append = entryPoint.append.map(resolvePath);
}
if (entryPoint.prepend) {
entryPoint.prepend = entryPoint.prepend.map(resolvePath);
}
}
});
loader(Object.keys(allMentionedModulesMap), () => {
let modules = <IBuildModuleInfo[]>loader.getBuildInfo();
let partialResult = emitEntryPoints(modules, entryPointsMap);
......@@ -171,7 +193,15 @@ function emitEntryPoints(modules:IBuildModuleInfo[], entryPoints:IEntryPointMap)
bundleData.bundles[moduleToBundle] = includedModules;
let res = emitEntryPoint(modulesMap, modulesGraph, moduleToBundle, includedModules);
let res = emitEntryPoint(
modulesMap,
modulesGraph,
moduleToBundle,
includedModules,
info.prepend,
info.append,
info.dest
);
result = result.concat(res.files);
for (let pluginName in res.usedPlugins) {
......@@ -355,10 +385,21 @@ interface IEmitEntryPointResult {
usedPlugins: IPluginMap;
}
function emitEntryPoint(modulesMap:IBuildModuleInfoMap, deps:IGraph, entryPoint:string, includedModules:string[]): IEmitEntryPointResult {
function emitEntryPoint(
modulesMap:IBuildModuleInfoMap,
deps:IGraph,
entryPoint:string,
includedModules:string[],
prepend: string[],
append: string[],
dest: string
): IEmitEntryPointResult {
if (!dest) {
dest = entryPoint + '.js';
}
let mainResult: IConcatFile = {
sources: [],
dest: entryPoint + '.js'
dest: dest
},
results: IConcatFile[] = [mainResult];
......@@ -416,6 +457,19 @@ function emitEntryPoint(modulesMap:IBuildModuleInfoMap, deps:IGraph, entryPoint:
}
});
let toIFile = (path):IFile => {
let contents = readFileAndRemoveBOM(path);
return {
path: path,
contents: contents
};
};
let toPrepend = (prepend||[]).map(toIFile);
let toAppend = (append||[]).map(toIFile);
mainResult.sources = toPrepend.concat(mainResult.sources).concat(toAppend);
return {
files: results,
usedPlugins: usedPlugins
......
{
"name": "monaco-editor-core",
"private": true,
"version": "0.7.0-next.5",
"version": "0.7.1",
"description": "A browser based code editor",
"author": "Microsoft Corporation",
"license": "MIT",
......
......@@ -9,7 +9,9 @@
let MonacoEnvironment = (<any>self).MonacoEnvironment;
let monacoBaseUrl = MonacoEnvironment && MonacoEnvironment.baseUrl ? MonacoEnvironment.baseUrl : '../../../';
importScripts(monacoBaseUrl + 'vs/loader.js');
if (typeof (<any>self).define !== 'function' || !(<any>self).define.amd) {
importScripts(monacoBaseUrl + 'vs/loader.js');
}
require.config({
baseUrl: monacoBaseUrl,
......
......@@ -1926,7 +1926,7 @@ var AMDLoader;
RequireFunc.config(global.require);
}
if (!isElectronRenderer) {
global.define = DefineFunc;
global.define = define = DefineFunc;
}
else {
define = function () {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册