mirror of
https://github.com/microsoft/vscode.git
synced 2026-02-21 02:11:11 +00:00
* Mangle exported functions For #180461 This prototype tries to mangle exported functions, saving a further 440kb from the bundle size * Fix missing call * Also try mangling top level exported consts too * Fixing errors * Don't run on build files * Skip a few more manglings and revert change to namespace * Skip a few more monaco files * Also mangle consts that shadow types This increases savings up to 3325 * Also mangle exported classes * Skip mangling more localization functions for now * Opt out pfs * Update build script * Run find locations task in parallel This should speed up compile * Cleanup before close * Limit workers to avoid hitting memory limit * Limit pool size * Skip one more mangling * Exclude entrypoints from mangling * Try to fix web build and clean up code * Exempt a few more projects * Exempt another file * Also exempt html * Skip mangling ext entrypoints * Use prefix that can't be confused with rpc calls * Fix max call stack error * Switch prefixes * Don't mangle ambient declarations * Use correct way of checking modifier flags * Workaround getCombinedModifierFlags not doing what I'd expect Maybe needs the checker to be enabled too? Just check parent chain instead for now * Clean up code and add logic showing how enum mangling could work * Remove a few more skipMangles Use entrypoints instead * Fix entrypoint name
84 lines
2.6 KiB
TypeScript
84 lines
2.6 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
interface ICSSPluginConfig {
|
|
disabled?: boolean;
|
|
}
|
|
|
|
/**
|
|
* Invoked by the loader at run-time
|
|
*
|
|
* @skipMangle
|
|
*/
|
|
export function load(name: string, req: AMDLoader.IRelativeRequire, load: AMDLoader.IPluginLoadCallback, config: AMDLoader.IConfigurationOptions): void {
|
|
config = config || {};
|
|
const cssConfig = <ICSSPluginConfig>(config['vs/css'] || {});
|
|
|
|
if (cssConfig.disabled) {
|
|
// the plugin is asked to not create any style sheets
|
|
load({});
|
|
return;
|
|
}
|
|
|
|
const cssUrl = req.toUrl(name + '.css');
|
|
loadCSS(name, cssUrl, () => {
|
|
load({});
|
|
}, (err: any) => {
|
|
if (typeof load.error === 'function') {
|
|
load.error('Could not find ' + cssUrl + '.');
|
|
}
|
|
});
|
|
}
|
|
|
|
function loadCSS(name: string, cssUrl: string, callback: () => void, errorback: (err: any) => void): void {
|
|
if (linkTagExists(name, cssUrl)) {
|
|
callback();
|
|
return;
|
|
}
|
|
createLinkTag(name, cssUrl, callback, errorback);
|
|
}
|
|
|
|
function linkTagExists(name: string, cssUrl: string): boolean {
|
|
const links = document.getElementsByTagName('link');
|
|
for (let i = 0, len = links.length; i < len; i++) {
|
|
const nameAttr = links[i].getAttribute('data-name');
|
|
const hrefAttr = links[i].getAttribute('href');
|
|
if (nameAttr === name || hrefAttr === cssUrl) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function createLinkTag(name: string, cssUrl: string, callback: () => void, errorback: (err: any) => void): void {
|
|
const linkNode = document.createElement('link');
|
|
linkNode.setAttribute('rel', 'stylesheet');
|
|
linkNode.setAttribute('type', 'text/css');
|
|
linkNode.setAttribute('data-name', name);
|
|
|
|
attachListeners(name, linkNode, callback, errorback);
|
|
linkNode.setAttribute('href', cssUrl);
|
|
|
|
const head = document.head || document.getElementsByTagName('head')[0];
|
|
head.appendChild(linkNode);
|
|
}
|
|
|
|
function attachListeners(name: string, linkNode: HTMLLinkElement, callback: () => void, errorback: (err: any) => void): void {
|
|
const unbind = () => {
|
|
linkNode.removeEventListener('load', loadEventListener);
|
|
linkNode.removeEventListener('error', errorEventListener);
|
|
};
|
|
const loadEventListener = (e: any) => {
|
|
unbind();
|
|
callback();
|
|
};
|
|
const errorEventListener = (e: any) => {
|
|
unbind();
|
|
errorback(e);
|
|
};
|
|
linkNode.addEventListener('load', loadEventListener);
|
|
linkNode.addEventListener('error', errorEventListener);
|
|
}
|