Skip to content

Commit c27a3a4

Browse files
authored
chore: 📦 Optimize npm package size (ant-design#23698)
* improve custom theme import path * reduce npm package size
1 parent f5153ab commit c27a3a4

8 files changed

+20
-16
lines changed

.antd-tools.config.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,14 @@ function finalizeCompile() {
6161

6262
function buildThemeFile(theme, vars) {
6363
// Build less entry file: dist/antd.${theme}.less
64-
fs.writeFileSync(
65-
path.join(process.cwd(), 'dist', `antd.${theme}.less`),
66-
`@import "../lib/style/${theme}.less";\n@import "../lib/style/components.less";`,
67-
);
68-
69-
// eslint-disable-next-line no-console
70-
console.log(`Built a entry less file to dist/antd.${theme}.less`);
71-
72-
if (theme === 'default') {
64+
if (theme !== 'default') {
65+
fs.writeFileSync(
66+
path.join(process.cwd(), 'dist', `antd.${theme}.less`),
67+
`@import "../lib/style/${theme}.less";\n@import "../lib/style/components.less";`,
68+
);
69+
// eslint-disable-next-line no-console
70+
console.log(`Built a entry less file to dist/antd.${theme}.less`);
71+
} else {
7372
fs.writeFileSync(
7473
path.join(process.cwd(), 'dist', `default-theme.js`),
7574
`module.exports = ${JSON.stringify(vars, null, 2)};\n`,

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ nohup.out
2525
_site
2626
_data
2727
dist
28+
report.html
2829
/lib
2930
/es
3031
elasticsearch-*
@@ -55,4 +56,4 @@ site/theme/template/Content/EditButton.jsx
5556
site/theme/template/Resources/*.jsx
5657
site/theme/template/Resources/**/*.jsx
5758
site/theme/template/NotFound.jsx
58-
scripts/previewEditor/index.html
59+
scripts/previewEditor/index.html

.npmignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
~*
2-
dist/report.html

docs/react/customize-theme.en-US.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ Follow [Use in create-react-app](/docs/react/use-with-create-react-app).
9797
Another approach to customize theme is creating a `less` file within variables to override `antd.less`.
9898

9999
```css
100-
@import '~antd/es/style/themes/default.less';
100+
@import '~antd/lib/style/themes/default.less';
101101
@import '~antd/dist/antd.less'; // Import Ant Design styles by less entry
102102
@import 'your-theme-file.less'; // variables to override above
103103
```
@@ -117,7 +117,7 @@ It's possible to configure webpack to load an alternate less file:
117117
```ts
118118
new webpack.NormalModuleReplacementPlugin( /node_modules\/antd\/lib\/style\/index\.less/, path.resolve(rootDir, 'src/myStylesReplacement.less') )
119119

120-
#antd { @import '~antd/es/style/core/index.less'; @import '~antd/es/style/themes/default.less'; }
120+
#antd { @import '~antd/lib/style/core/index.less'; @import '~antd/lib/style/themes/default.less'; }
121121
```
122122

123123
Where the src/myStylesReplacement.less file loads the same files as the index.less file, but loads them within the scope of a top-level selector : the result is that all of the "global" styles are being applied with the #antd scope.

docs/react/customize-theme.zh-CN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ module.exports = {
9797
另外一种方式是建立一个单独的 `less` 变量文件,引入这个文件覆盖 `antd.less` 里的变量。
9898

9999
```css
100-
@import '~antd/es/style/themes/default.less';
100+
@import '~antd/lib/style/themes/default.less';
101101
@import '~antd/dist/antd.less'; // 引入官方提供的 less 样式入口文件
102102
@import 'your-theme-file.less'; // 用于覆盖上面定义的变量
103103
```

docs/spec/colors.en-US.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ We provide Less and JavaScript usage for developers.
5959
- **Less**
6060

6161
```less
62-
@import '~antd/es/style/themes/default.less', .selector {
62+
@import '~antd/lib/style/themes/default.less';
63+
64+
.selector {
6365
color: @blue-5;
6466
background-color: @gold-2;
6567
}

docs/spec/colors.zh-CN.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ ReactDOM.render(<ColorPaletteTool />, mountNode);
6767
- **Less**
6868

6969
```less
70-
@import '~antd/es/style/themes/default.less', .selector {
70+
@import '~antd/lib/style/themes/default.less';
71+
72+
.selector {
7173
color: @blue-5;
7274
background-color: @gold-2;
7375
}

webpack.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ if (process.env.RUN_ENV === 'PRODUCTION') {
7474
new BundleAnalyzerPlugin({
7575
analyzerMode: 'static',
7676
openAnalyzer: false,
77+
reportFilename: '../report.html',
7778
}),
7879
);
7980
}

0 commit comments

Comments
 (0)