Uh oh!
There was an error while loading. Please reload this page.
forked from microsoft/vscode
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmangle-loader.js
More file actions
Latest commit
58 lines (49 loc) · 1.75 KB
/
Copy pathmangle-loader.js
File metadata and controls
58 lines (49 loc) · 1.75 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
// @ts-check
constfs=require('fs');
constwebpack=require('webpack');
constfancyLog=require('fancy-log');
constansiColors=require('ansi-colors');
const{ Mangler }=require('../build/lib/mangleTypeScript');
/**
* Map of project paths to mangled file contents
*
* @type {Map<string, Map<string, { out: string; sourceMap?: string }>>}
*/
constmangleMap=newMap();
/**
* @param {string} projectPath
*/
functiongetMangledFileContents(projectPath){
letentry=mangleMap.get(projectPath);
if(!entry){
constlog=(...data)=>fancyLog(ansiColors.blue('[mangler]'), ...data);
log(`Mangling ${projectPath}`);
constts2tsMangler=newMangler(projectPath,log);
entry=ts2tsMangler.computeNewFileContents();
mangleMap.set(projectPath,entry);
}
returnentry;
}
/**
* @type {webpack.LoaderDefinitionFunction}
*/
module.exports=asyncfunction(source,sourceMap,meta){
if(this.mode!=='production'){
// Only enable mangling in production builds
returnsource;
}
if(source!==fs.readFileSync(this.resourcePath).toString()){
// File content has changed by previous webpack steps.
// Skip mangling.
returnsource;
}
constoptions=this.getOptions();
constcallback=this.async();
constfileContentsMap=getMangledFileContents(options.configFile);
constnewContents=fileContentsMap.get(this.resourcePath);
callback(null,newContents?.out??source,sourceMap,meta);
};