forked from microsoft/vscode
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmangle-loader.js
More file actions
34 lines (28 loc) · 1.05 KB
/
mangle-loader.js
File metadata and controls
34 lines (28 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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);
};