Skip to content

Commit d4dfdde

Browse files
Fixed antd icons issue with ESM loading (#4872)
1 parent ea3b763 commit d4dfdde

File tree

7 files changed

+26
-6
lines changed

7 files changed

+26
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ should change the heading of the (upcoming) version to include a major version b
2828
## Dev / docs / playground
2929

3030
- Updated the `playground` to use the css files for `@rjsf/shadcn` from the CDN connected with github, pointing to the new resources directory
31+
- Added new `antdIconsReplacer.ts` and used it in `@rjsf/antd` during build time to append `.js` onto imports of `@antd/icons` to fix es build issues on webpack and vite
3132

3233
# 6.1.0
3334

packages/antd/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
}
3535
},
3636
"scripts": {
37-
"compileReplacer": "tsc -p tsconfig.replacer.json && move-file lodashReplacer.js lodashReplacer.cjs",
37+
"compileReplacer": "tsc -p tsconfig.replacer.json && move-file lodashReplacer.js lodashReplacer.cjs && move-file antdIconsReplacer.js antdIconsReplacer.cjs",
3838
"build:ts": "npm run compileReplacer && rimraf ./lib && tsc -b tsconfig.build.json && tsc-alias -p tsconfig.build.json",
3939
"build:cjs": "esbuild ./src/index.ts --bundle --outfile=dist/index.cjs --sourcemap --packages=external --format=cjs",
4040
"build:esm": "esbuild ./src/index.ts --bundle --outfile=dist/antd.esm.js --sourcemap --packages=external --format=esm",

packages/antd/tsconfig.build.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
"replacers": {
1616
"lodash": {
1717
"enabled": true,
18-
"file": "lodashReplacer.cjs"
18+
"file": "lodashReplacer.cjs",
19+
},
20+
"antdIcons": {
21+
"enabled": true,
22+
"file": "antdIconsReplacer.cjs"
1923
}
2024
}
2125
}

packages/antd/tsconfig.replacer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"skipLibCheck": true,
77
},
88
"files": [
9-
"../../tsc-alias-replacer/lodashReplacer.ts"
9+
"../../tsc-alias-replacer/lodashReplacer.ts",
10+
"../../tsc-alias-replacer/antdIconsReplacer.ts"
1011
],
1112
"exclude": [
1213
"./src",

tsc-alias-replacer/ajvReplacer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { AliasReplacerArguments } from 'tsc-alias';
77
*/
88
export default function ajvReplacer({ orig }: AliasReplacerArguments): string {
99
if (orig.startsWith("from 'ajv/dist/standalone")) {
10-
const origLodashEs = orig.substring(0, orig.length - 1);
11-
return `${origLodashEs}/index.js'`;
10+
const origAjv = orig.substring(0, orig.length - 1);
11+
return `${origAjv}/index.js'`;
1212
}
1313

1414
return orig;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { AliasReplacerArguments } from 'tsc-alias';
2+
3+
/** A `tsc-alias` replacer that fixes up the imports `from 'ajv/dist/standalone'` to be
4+
* `from `ajv/dist/standalone/index.js`
5+
*
6+
* @param orig - The original import name
7+
*/
8+
export default function antdIconsReplacer({ orig }: AliasReplacerArguments): string {
9+
if (orig.startsWith("from '@ant-design/icons/")) {
10+
const origIcons = orig.substring(0, orig.length - 1);
11+
return `${origIcons}.js'`;
12+
}
13+
14+
return orig;
15+
}

tsc-alias-replacer/lodashReplacer.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { AliasReplacerArguments } from 'tsc-alias';
77
export default function lodashReplacer({ orig }: AliasReplacerArguments): string {
88
if (orig.startsWith("from 'lodash/")) {
99
const origLodashEs = orig.substring(0, orig.length - 1).replace('lodash/', 'lodash-es/');
10-
// console.log(origLodashEs);
1110
return `${origLodashEs}.js'`;
1211
}
1312

0 commit comments

Comments
 (0)