diff --git a/.antd-tools.config.js b/.antd-tools.config.js index 247ce167ba..4fddb635f2 100644 --- a/.antd-tools.config.js +++ b/.antd-tools.config.js @@ -25,7 +25,7 @@ function finalizeCompile() { componentsLessContent += `@import "../${path.posix.join( file, 'style', - 'index.less', + 'index-pure.less', )}";\n`; } }); @@ -35,6 +35,24 @@ function finalizeCompile() { ); }); } + + // Create entry for babel plugin import + function patchEntry(styleEntry) { + if (fs.existsSync(styleEntry)) { + fs.writeFileSync( + path.join(styleEntry, 'style', 'index-default.less'), + [ + // Inject variable + '@root-entry-name: default;', + // Point to origin file + "@import './index';", + ].join('\n'), + ); + } + } + + patchEntry(path.join(process.cwd(), 'lib')); + patchEntry(path.join(process.cwd(), 'es')); } function buildThemeFile(theme, vars) { @@ -78,7 +96,7 @@ function finalizeDist() { // Build less entry file: dist/antd.less fs.writeFileSync( path.join(process.cwd(), 'dist', 'antd.less'), - '@import "../lib/style/index.less";\n@import "../lib/style/components.less";', + '@import "../lib/style/default.less";\n@import "../lib/style/components.less";', ); // eslint-disable-next-line no-console fs.writeFileSync( @@ -126,25 +144,26 @@ module.exports = { } } -function isComponentStyle(file) { +function isComponentStyleEntry(file) { return file.path.match(/style(\/|\\)index\.tsx/); } function needTransformStyle(content) { - return content.includes('./index.less'); + return content.includes('../../style/index.less') || content.includes('./index.less'); } module.exports = { compile: { transformTSFile(file) { - if (isComponentStyle(file)) { + if (isComponentStyleEntry(file)) { let content = file.contents.toString(); if (needTransformStyle(content)) { const cloneFile = file.clone(); // Origin - content = content.replace('./index.less', './index-default.less'); + content = content.replace('../../style/index.less', '../../style/index-default.less'); + // content = content.replace('./index.less', './index-default.less'); cloneFile.contents = Buffer.from(content); return cloneFile; @@ -152,23 +171,31 @@ module.exports = { } }, transformFile(file) { - if (isComponentStyle(file)) { - const content = file.contents.toString(); - - if (needTransformStyle(content)) { - const cloneFile = file.clone(); - cloneFile.contents = Buffer.from( + if (isComponentStyleEntry(file)) { + const indexLessFilePath = file.path.replace('index.tsx', 'index.less'); + + if (fs.existsSync(indexLessFilePath)) { + // We put origin `index.less` file to `index-pure.less` + const pureFile = file.clone(); + pureFile.contents = Buffer.from(fs.readFileSync(indexLessFilePath, 'utf8')); + pureFile.path = pureFile.path.replace('index.tsx', 'index-pure.less'); + + // Rewrite `index.less` file with `root-entry-name` + const indexLessFile = file.clone(); + indexLessFile.contents = Buffer.from( [ // Inject variable '@root-entry-name: default;', // Point to origin file - "@import './index';", + "@import './index-pure.less';", ].join('\n\n'), ); - cloneFile.path = cloneFile.path.replace('index.tsx', 'index-default.less'); - return cloneFile; + indexLessFile.path = indexLessFile.path.replace('index.tsx', 'index.less'); + + return [indexLessFile, pureFile]; } } + return []; }, lessConfig: { diff --git a/components/cascader/style/rtl.less b/components/cascader/style/rtl.less index 2700993ac8..c70bf1dd3a 100644 --- a/components/cascader/style/rtl.less +++ b/components/cascader/style/rtl.less @@ -1,4 +1,6 @@ -@import (reference) './index'; +// We can not import reference of `./index` directly since it will make dead loop in less +@import (reference) '../../style/themes/index'; +@cascader-prefix-cls: ~'@{ant-prefix}-cascader'; .@{cascader-prefix-cls}-rtl { .@{cascader-prefix-cls}-menu-item { diff --git a/components/drawer/style/customize.less b/components/drawer/style/customize.less deleted file mode 100644 index 59bc05695a..0000000000 --- a/components/drawer/style/customize.less +++ /dev/null @@ -1,3 +0,0 @@ -@import './index.less'; - -.popover-customize-bg(@drawer-prefix-cls, @popover-background); diff --git a/components/drawer/style/index.less b/components/drawer/style/index.less index 79cde6c2b0..77efacf49d 100644 --- a/components/drawer/style/index.less +++ b/components/drawer/style/index.less @@ -1,5 +1,6 @@ @import '../../style/themes/index'; @import '../../style/mixins/index'; @import './drawer'; -@import './customize'; @import './rtl'; + +.popover-customize-bg(@drawer-prefix-cls, @popover-background); diff --git a/components/dropdown/style/status.less b/components/dropdown/style/status.less index 327cf488ab..e370a8722b 100644 --- a/components/dropdown/style/status.less +++ b/components/dropdown/style/status.less @@ -1,4 +1,6 @@ -@import './index'; +@import (reference) '../../style/themes/index'; + +@dropdown-prefix-cls: ~'@{ant-prefix}-dropdown'; .@{dropdown-prefix-cls}-menu-item { &&-danger { diff --git a/components/form/style/components.less b/components/form/style/components.less index 4dc1b2147c..c57e8b9c76 100644 --- a/components/form/style/components.less +++ b/components/form/style/components.less @@ -1,4 +1,7 @@ -@import './index'; +@import (reference) '../../style/themes/index'; + +@form-prefix-cls: ~'@{ant-prefix}-form'; +@form-item-prefix-cls: ~'@{form-prefix-cls}-item'; // ================================================================ // = Children Component = diff --git a/components/form/style/horizontal.less b/components/form/style/horizontal.less index 83b664d448..80c5f8250d 100644 --- a/components/form/style/horizontal.less +++ b/components/form/style/horizontal.less @@ -1,4 +1,7 @@ -@import './index'; +@import (reference) '../../style/themes/index'; + +@form-prefix-cls: ~'@{ant-prefix}-form'; +@form-item-prefix-cls: ~'@{form-prefix-cls}-item'; .@{form-prefix-cls}-horizontal { .@{form-item-prefix-cls}-label { diff --git a/components/form/style/inline.less b/components/form/style/inline.less index 6cd0c4d40e..63946752da 100644 --- a/components/form/style/inline.less +++ b/components/form/style/inline.less @@ -1,4 +1,7 @@ -@import './index'; +@import (reference) '../../style/themes/index'; + +@form-prefix-cls: ~'@{ant-prefix}-form'; +@form-item-prefix-cls: ~'@{form-prefix-cls}-item'; .@{form-prefix-cls}-inline { display: flex; diff --git a/components/form/style/status.less b/components/form/style/status.less index e5dd511eb4..4817031c93 100644 --- a/components/form/style/status.less +++ b/components/form/style/status.less @@ -1,4 +1,7 @@ -@import './index.less'; +@import (reference) '../../style/themes/index'; + +@form-prefix-cls: ~'@{ant-prefix}-form'; +@form-item-prefix-cls: ~'@{form-prefix-cls}-item'; .@{form-item-prefix-cls} { // ================================================================ diff --git a/components/form/style/vertical.less b/components/form/style/vertical.less index 8e2249554e..ee00b204d7 100644 --- a/components/form/style/vertical.less +++ b/components/form/style/vertical.less @@ -1,4 +1,7 @@ -@import './index'; +@import (reference) '../../style/themes/index'; + +@form-prefix-cls: ~'@{ant-prefix}-form'; +@form-item-prefix-cls: ~'@{form-prefix-cls}-item'; // ================== Label ================== .make-vertical-layout-label() { diff --git a/components/input/style/affix.less b/components/input/style/affix.less index 24a69702cf..c7d55d9312 100644 --- a/components/input/style/affix.less +++ b/components/input/style/affix.less @@ -1,6 +1,8 @@ -@import './index'; @import './mixin'; +@import (reference) '../../style/themes/index'; +@input-prefix-cls: ~'@{ant-prefix}-input'; + @input-affix-margin: 4px; .@{ant-prefix}-input { diff --git a/components/input/style/allow-clear.less b/components/input/style/allow-clear.less index 3356c26e70..8f548c8a80 100644 --- a/components/input/style/allow-clear.less +++ b/components/input/style/allow-clear.less @@ -1,4 +1,5 @@ -@import './index'; +@import (reference) '../../style/themes/index'; +@input-prefix-cls: ~'@{ant-prefix}-input'; // ========================= Input ========================= .@{iconfont-css-prefix}.@{ant-prefix}-input-clear-icon { diff --git a/components/list/style/customize.less b/components/list/style/customize.less index bbad35b7bc..d0e2b84a83 100644 --- a/components/list/style/customize.less +++ b/components/list/style/customize.less @@ -1,5 +1,6 @@ -@import './index.less'; +@import '../../style/themes/index'; +@list-prefix-cls: ~'@{ant-prefix}-list'; @card-prefix-cls: ~'@{ant-prefix}-card'; .@{list-prefix-cls} { diff --git a/components/menu/style/status.less b/components/menu/style/status.less index 5e5d66c057..225f0e9c23 100644 --- a/components/menu/style/status.less +++ b/components/menu/style/status.less @@ -1,4 +1,5 @@ -@import './index'; +@import (reference) '../../style/themes/index'; +@menu-prefix-cls: ~'@{ant-prefix}-menu'; .@{menu-prefix-cls} { // Danger diff --git a/components/modal/style/customize.less b/components/modal/style/customize.less deleted file mode 100644 index f8e1abbbff..0000000000 --- a/components/modal/style/customize.less +++ /dev/null @@ -1,3 +0,0 @@ -@import './index.less'; - -.popover-customize-bg(@dialog-prefix-cls, @popover-background); diff --git a/components/modal/style/index.less b/components/modal/style/index.less index 0f128a2e0b..5acc2608d4 100644 --- a/components/modal/style/index.less +++ b/components/modal/style/index.less @@ -2,5 +2,6 @@ @import '../../style/mixins/index'; @import './modal'; @import './confirm'; -@import './customize'; @import './rtl'; + +.popover-customize-bg(@dialog-prefix-cls, @popover-background); diff --git a/components/notification/style/customize.less b/components/notification/style/customize.less deleted file mode 100644 index 65a7d2f6be..0000000000 --- a/components/notification/style/customize.less +++ /dev/null @@ -1,3 +0,0 @@ -@import './index.less'; - -.popover-customize-bg(@notification-prefix-cls, @popover-background); diff --git a/components/notification/style/index.less b/components/notification/style/index.less index 7ded96f53d..cc654760ae 100644 --- a/components/notification/style/index.less +++ b/components/notification/style/index.less @@ -1,6 +1,7 @@ @import '../../style/themes/index'; @import '../../style/mixins/index'; -@import './customize.less'; + +.popover-customize-bg(@notification-prefix-cls, @popover-background); @notification-prefix-cls: ~'@{ant-prefix}-notification'; @notification-width: 384px; diff --git a/components/popover/style/customize.less b/components/popover/style/customize.less deleted file mode 100644 index a62efbd9ca..0000000000 --- a/components/popover/style/customize.less +++ /dev/null @@ -1,3 +0,0 @@ -@import './index.less'; - -.popover-customize-bg(@popover-prefix-cls, @popover-background); diff --git a/components/select/style/multiple.less b/components/select/style/multiple.less index 737c30b7d9..8da093063f 100644 --- a/components/select/style/multiple.less +++ b/components/select/style/multiple.less @@ -1,4 +1,5 @@ -@import './index'; +@import (reference) '../../style/themes/index'; +@select-prefix-cls: ~'@{ant-prefix}-select'; @select-overflow-prefix-cls: ~'@{select-prefix-cls}-selection-overflow'; @select-multiple-item-border-width: 1px; diff --git a/components/select/style/single.less b/components/select/style/single.less index e70052a15f..a4c7e21416 100644 --- a/components/select/style/single.less +++ b/components/select/style/single.less @@ -1,4 +1,5 @@ -@import './index'; +@import (reference) '../../style/themes/index'; +@select-prefix-cls: ~'@{ant-prefix}-select'; @selection-item-padding: ceil(@font-size-base * 1.25); diff --git a/components/style/default.less b/components/style/default.less new file mode 100644 index 0000000000..ecec084536 --- /dev/null +++ b/components/style/default.less @@ -0,0 +1,4 @@ +// This is same as `index.less` but given `root-entry-name` for `dist/antd.less` usage +@root-entry-name: default; + +@import './index'; diff --git a/components/switch/style/rtl.less b/components/switch/style/rtl.less index 0a5d52b587..7a7de94bba 100644 --- a/components/switch/style/rtl.less +++ b/components/switch/style/rtl.less @@ -1,9 +1,11 @@ @import '../../style/themes/index'; @import '../../style/mixins/index'; -@import './index'; @switch-prefix-cls: ~'@{ant-prefix}-switch'; +@switch-pin-size: @switch-height - 4px; +@switch-sm-pin-size: @switch-sm-height - 4px; + .@{switch-prefix-cls}-rtl { direction: rtl; diff --git a/components/table/style/bordered.less b/components/table/style/bordered.less index 938e25059d..7c30103a89 100644 --- a/components/table/style/bordered.less +++ b/components/table/style/bordered.less @@ -1,6 +1,8 @@ -@import './index'; @import './size'; +@import (reference) '../../style/themes/index'; +@table-prefix-cls: ~'@{ant-prefix}-table'; + @table-border: @border-width-base @border-style-base @table-border-color; .@{table-prefix-cls}.@{table-prefix-cls}-bordered { diff --git a/components/table/style/size.less b/components/table/style/size.less index f34a63c13e..c80680a7cb 100644 --- a/components/table/style/size.less +++ b/components/table/style/size.less @@ -1,4 +1,6 @@ -@import './index'; +@import (reference) '../../style/themes/index'; + +@table-prefix-cls: ~'@{ant-prefix}-table'; .table-size(@size, @padding-vertical, @padding-horizontal, @font-size) { .@{table-prefix-cls}.@{table-prefix-cls}-@{size} { diff --git a/components/tabs/style/card.less b/components/tabs/style/card.less index 471da77069..ccf23c4f3c 100644 --- a/components/tabs/style/card.less +++ b/components/tabs/style/card.less @@ -1,6 +1,7 @@ @import '../../style/themes/index'; @import '../../style/mixins/index'; -@import './index'; + +@tab-prefix-cls: ~'@{ant-prefix}-tabs'; .@{tab-prefix-cls}-card { > .@{tab-prefix-cls}-nav, diff --git a/components/tabs/style/dropdown.less b/components/tabs/style/dropdown.less index 7cbd909415..35e10f88b2 100644 --- a/components/tabs/style/dropdown.less +++ b/components/tabs/style/dropdown.less @@ -1,6 +1,7 @@ @import '../../style/themes/index'; @import '../../style/mixins/index'; -@import './index'; + +@tab-prefix-cls: ~'@{ant-prefix}-tabs'; .@{tab-prefix-cls}-dropdown { .reset-component(); diff --git a/components/tabs/style/position.less b/components/tabs/style/position.less index 9da9bb8ad1..f670fef415 100644 --- a/components/tabs/style/position.less +++ b/components/tabs/style/position.less @@ -1,4 +1,5 @@ -@import './index'; +@import '../../style/themes/index'; +@tab-prefix-cls: ~'@{ant-prefix}-tabs'; .@{tab-prefix-cls} { // ========================== Top & Bottom ========================== diff --git a/components/tabs/style/size.less b/components/tabs/style/size.less index 43a75f1797..03c0fea9a4 100644 --- a/components/tabs/style/size.less +++ b/components/tabs/style/size.less @@ -1,6 +1,7 @@ @import '../../style/themes/index'; @import '../../style/mixins/index'; -@import './index'; + +@tab-prefix-cls: ~'@{ant-prefix}-tabs'; .@{tab-prefix-cls} { &-small { diff --git a/components/transfer/style/customize.less b/components/transfer/style/customize.less index 614df0855e..042a0cb17e 100644 --- a/components/transfer/style/customize.less +++ b/components/transfer/style/customize.less @@ -1,4 +1,6 @@ -@import './index.less'; +@import '../../style/themes/index'; + +@transfer-prefix-cls: ~'@{ant-prefix}-transfer'; @table-prefix-cls: ~'@{ant-prefix}-table'; @input-prefix-cls: ~'@{ant-prefix}-input';