Skip to content

Commit

Permalink
add modifyDefaultConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshuai2144 committed Apr 6, 2020
1 parent 90dd8d6 commit a034530
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@types/node": "^12.12.14",
"father-build": "^1.8.0",
"np": "^5.0.3",
"umi": "^3.0.0-beta.29"
"umi": "^3.0.18"
},
"files": [
"dist",
Expand Down
48 changes: 40 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,39 @@ interface themeConfig {
modifyVars?: { [key: string]: string };
}

export default function(api: IApi) {
export default function (api: IApi) {
api.modifyDefaultConfig((config) => {
config.cssLoader = {
modules: {
getLocalIdent: (
context: {
resourcePath: string;
},
_: string,
localName: string,
) => {
if (
context.resourcePath.includes('node_modules') ||
context.resourcePath.includes('ant.design.pro.less') ||
context.resourcePath.includes('global.less')
) {
return localName;
}
const match = context.resourcePath.match(/src(.*)/);
if (match && match[1]) {
const antdProPath = match[1].replace('.less', '');
const arr = winPath(antdProPath)
.split('/')
.map((a: string) => a.replace(/([A-Z])/g, '-$1'))
.map((a: string) => a.toLowerCase());
return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
}
return localName;
},
},
};
return config;
});
// 给一个默认的配置
let options: {
theme: themeConfig[];
Expand Down Expand Up @@ -65,20 +97,20 @@ export default function(api: IApi) {
buildCss(
cwd,
options.theme.map(
theme => ({
(theme) => ({
...theme,
fileName: winPath(join(outputPath, 'theme', theme.fileName)),
}),
{
min: true,
...options,
}
)
},
),
)
.then(() => {
api.logger.log('🎊 build theme success');
})
.catch(e => {
.catch((e) => {
console.log(e);
});
});
Expand All @@ -105,18 +137,18 @@ export default function(api: IApi) {

buildCss(
cwd,
options.theme.map(theme => ({
options.theme.map((theme) => ({
...theme,
fileName: winPath(join(themeTemp, 'theme', theme.fileName)),
})),
{
...options,
}
},
)
.then(() => {
api.logger.log('🎊 build theme success');
})
.catch(e => {
.catch((e) => {
console.log(e);
});
});
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"sourceMap": true,
"baseUrl": ".",
"jsx": "react",
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,
"moduleResolution": "node",
"forceConsistentCasingInFileNames": true,
Expand Down

0 comments on commit a034530

Please sign in to comment.