Skip to content

Commit 070fe67

Browse files
committed
fix: reduce MUI size by using @swc/plugin-transform-imports
1 parent f371b78 commit 070fe67

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ tsconfig.tsbuildinfo
1515
.eslintcache
1616
node_modules
1717

18+
.swc
1819
.next
1920
.vercel
2021
coverage

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
"@rollup/plugin-node-resolve": "^15.0.1",
8383
"@rollup/plugin-replace": "^5.0.2",
8484
"@swc/core": "^1.3.26",
85+
"@swc/plugin-transform-imports": "^1.5.36",
8586
"@testing-library/react": "^13.4.0",
8687
"@types/node": "^18.11.18",
8788
"@types/react": "^18.0.26",

rollup.config.ts

+19-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const external = [
2727
'@emotion/react/jsx-runtime',
2828
'@emotion/react/jsx-dev-runtime',
2929
'@mui/material',
30-
'@mui/material/styles',
30+
/@mui\/material\/.*/,
3131
'copy-to-clipboard',
3232
'zustand',
3333
'zustand/context',
@@ -48,7 +48,9 @@ const outputMatrix = (
4848
format,
4949
banner: `/// <reference types="./${baseName}.d.ts" />`,
5050
globals: external.reduce((object, module) => {
51-
object[module] = module
51+
if (typeof module === 'string') {
52+
object[module] = module
53+
}
5254
return object
5355
}, {} as Record<string, string>)
5456
}))
@@ -102,6 +104,20 @@ const buildMatrix = (input: string, output: string, config: {
102104
runtime: 'automatic',
103105
importSource: '@emotion/react'
104106
}
107+
},
108+
experimental: {
109+
plugins: config.browser
110+
? []
111+
: [
112+
[
113+
'@swc/plugin-transform-imports',
114+
{
115+
'@mui/material': {
116+
transform: '@mui/material/{{member}}'
117+
}
118+
}
119+
]
120+
]
105121
}
106122
}
107123
}))
@@ -125,7 +141,7 @@ const dtsMatrix = (): RollupOptions[] => {
125141

126142
const build: RollupOptions[] = [
127143
buildMatrix('./src/index.tsx', 'index', {
128-
format: ['es', 'umd'],
144+
format: ['es', 'cjs'],
129145
browser: false,
130146
dts: true
131147
}),

yarn.lock

+8
Original file line numberDiff line numberDiff line change
@@ -1747,6 +1747,13 @@ __metadata:
17471747
languageName: node
17481748
linkType: hard
17491749

1750+
"@swc/plugin-transform-imports@npm:^1.5.36":
1751+
version: 1.5.36
1752+
resolution: "@swc/plugin-transform-imports@npm:1.5.36"
1753+
checksum: b47cbb9bdd29d20ac391050ac19afe862cc3bd86c17de5405789ff2e815e710d4ad2ab3356427c73a0b6da11f8757f707171cbd2ad325970f29af525dfb654e2
1754+
languageName: node
1755+
linkType: hard
1756+
17501757
"@testing-library/dom@npm:^8.5.0":
17511758
version: 8.18.1
17521759
resolution: "@testing-library/dom@npm:8.18.1"
@@ -1810,6 +1817,7 @@ __metadata:
18101817
"@rollup/plugin-node-resolve": ^15.0.1
18111818
"@rollup/plugin-replace": ^5.0.2
18121819
"@swc/core": ^1.3.26
1820+
"@swc/plugin-transform-imports": ^1.5.36
18131821
"@testing-library/react": ^13.4.0
18141822
"@types/node": ^18.11.18
18151823
"@types/react": ^18.0.26

0 commit comments

Comments
 (0)