-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
45 lines (40 loc) · 1.16 KB
/
index.ts
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
import Less from 'less'
import path from 'path'
import { normalizePath } from './utils'
// ref: less-plugin-module-resolver
// https://github.com/bundle-matters/less-plugin-module-resolver/blob/main/src/alias-file-manager.ts
export class LessPluginRemoveAntdGlobalStyles implements Less.Plugin {
constructor() {}
public install(_less: LessStatic, pluginManager: Less.PluginManager): void {
pluginManager.addFileManager(new FileManager())
}
}
class FileManager extends Less.FileManager {
constructor() {
super()
}
public supports(
filename: string,
currentDirectory: string,
_options: Less.LoadFileOptions,
_environment: Less.Environment
): boolean {
if (filename.includes('global')) {
// match antd global style file
const fullPath = normalizePath(path.join(currentDirectory, filename))
if (
fullPath.includes('antd/es/style/core/global') ||
fullPath.includes('antd/lib/style/core/global')
) {
return true
}
}
return false
}
public async loadFile(): Promise<Less.FileLoadResult> {
return {
filename: 'dummy-empty-global-style.less',
contents: '',
}
}
}