This repository has been archived by the owner on Sep 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ruleExtend.js
48 lines (47 loc) · 1.69 KB
/
ruleExtend.js
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
let ruleExtend = {
ignoreCheckNewModuleName: (moduleName) => { // 忽略检查新模块名称 !!警告:规则配置不当可能会造成死循环!!
return false;
},
moduleName: (moduleName) => { // 模块名称
return (new RegExp('^moduleName$')).test(moduleName);
},
importType: {
importSpecifier: { // 原导入类型(小驼峰) <importSpecifier|importDefaultSpecifier|importNamespaceSpecifier>
transforms: (importType, moduleName, importedName, localName) => {
return [
{
newImportType: 'ImportDefaultSpecifier', // 新导入类型(大驼峰) <ImportSpecifier|ImportDefaultSpecifier|ImportNamespaceSpecifier>
newModuleName: `${moduleName}/path/${importedName}`, // 新模块名称
newImportedName: importedName, // 新导入名称
newLocalName: localName // 新本地名称
}
];
}
},
importDefaultSpecifier: {
transforms: (importType, moduleName, importedName, localName) => {
return [
{
newImportType: 'ImportSpecifier',
newModuleName: `${moduleName}/path/${importedName}`,
newImportedName: 'default',
newLocalName: localName
}
];
}
},
importNamespaceSpecifier: {
transforms: (importType, moduleName, importedName, localName) => {
return [
{
newImportType: 'ImportDefaultSpecifier',
newModuleName: `${moduleName}/path/${importedName}`,
newImportedName: importedName,
newLocalName: localName
}
];
}
}
}
}
module.exports = ruleExtend;