mirror of
https://github.com/Microsoft/vscode
synced 2024-10-02 17:32:41 +00:00
Added mangling loader for ts files in extensions
This commit is contained in:
parent
4a040f6186
commit
0b9121953f
34
extensions/mangle-loader.js
Normal file
34
extensions/mangle-loader.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
// @ts-check
|
||||
|
||||
const webpack = require('webpack');
|
||||
const { Mangler } = require('../build/lib/mangleTypeScript');
|
||||
|
||||
let map;
|
||||
/**
|
||||
* @param {string} projectPath
|
||||
*/
|
||||
function getMangledFileContents(projectPath) {
|
||||
if (!map) {
|
||||
const ts2tsMangler = new Mangler(projectPath, console.log);
|
||||
map = ts2tsMangler.computeNewFileContents();
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {webpack.LoaderDefinitionFunction}
|
||||
*/
|
||||
module.exports = async function (source, sourceMap, meta) {
|
||||
const options = this.getOptions();
|
||||
const callback = this.async();
|
||||
|
||||
const fileContentsMap = getMangledFileContents(options.configFile);
|
||||
|
||||
const newContents = fileContentsMap.get(this.resourcePath);
|
||||
callback(null, newContents ?? source, sourceMap, meta);
|
||||
};
|
|
@ -7,13 +7,18 @@ import * as vscode from 'vscode';
|
|||
import { MarkdownItEngine } from '../markdownEngine';
|
||||
import { MarkdownContributionProvider, MarkdownContributions } from '../markdownExtensions';
|
||||
import { githubSlugifier } from '../slugify';
|
||||
import { Disposable } from '../util/dispose';
|
||||
import { nulLogger } from './nulLogging';
|
||||
|
||||
const emptyContributions = new class extends Disposable implements MarkdownContributionProvider {
|
||||
const emptyContributions = new class implements MarkdownContributionProvider {
|
||||
readonly extensionUri = vscode.Uri.file('/');
|
||||
readonly contributions = MarkdownContributions.Empty;
|
||||
readonly onContributionsChanged = this._register(new vscode.EventEmitter<this>()).event;
|
||||
|
||||
private readonly _onContributionsChanged = new vscode.EventEmitter<this>();
|
||||
readonly onContributionsChanged = this._onContributionsChanged.event;
|
||||
|
||||
dispose() {
|
||||
this._onContributionsChanged.dispose();
|
||||
}
|
||||
};
|
||||
|
||||
export function createNewMarkdownEngine(): MarkdownItEngine {
|
||||
|
|
|
@ -47,7 +47,12 @@ function withNodeDefaults(/**@type WebpackConfig*/extConfig) {
|
|||
'sourceMap': true,
|
||||
}
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
loader: path.resolve(__dirname, './mangle-loader.js'),
|
||||
options: {
|
||||
configFile: path.join(extConfig.context, 'tsconfig.json')
|
||||
},
|
||||
},]
|
||||
}]
|
||||
},
|
||||
externals: {
|
||||
|
@ -125,7 +130,14 @@ function withBrowserDefaults(/**@type WebpackConfig*/extConfig, /** @type Additi
|
|||
},
|
||||
...(additionalOptions ? {} : { configFile: additionalOptions.configFile })
|
||||
}
|
||||
}]
|
||||
},
|
||||
{
|
||||
loader: path.resolve(__dirname, './mangle-loader.js'),
|
||||
options: {
|
||||
configFile: path.join(extConfig.context, additionalOptions?.configFile ?? 'tsconfig.json')
|
||||
},
|
||||
},
|
||||
]
|
||||
}]
|
||||
},
|
||||
externals: {
|
||||
|
|
Loading…
Reference in a new issue