Skip to content

Commit

Permalink
Fix importing icons when using Next.js SSG/SSR, for real this time.
Browse files Browse the repository at this point in the history
  • Loading branch information
leMaik committed May 7, 2024
1 parent 60706c2 commit e1d02a5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
16 changes: 10 additions & 6 deletions generate-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ function checkNameClashes (icons) {
fse.mkdirpSync(path.join(__dirname, 'package', 'esm', 'light'))

for (const { name, filename, svgPath } of icons) {
const code = `import createIcon from './util/createIcon'
export default createIcon('${svgPath}', '${name}')
`
const code = `
"use client";
import createIcon from './util/createIcon'
export default createIcon('${svgPath}', '${name}')
`

// es module
fse.writeFileSync(path.join(__dirname, 'package', 'esm', `${filename || name}.js`), babel.transform(code, {
Expand All @@ -70,9 +72,11 @@ function checkNameClashes (icons) {
}

for (const { name, filename, svgPath } of lightIcons) {
const code = `import createIcon from '../util/createIcon'
export default createIcon('${svgPath}', '${name}')
`
const code = `
"use client";
import createIcon from '../util/createIcon'
export default createIcon('${svgPath}', '${name}')
`

// es module
fse.writeFileSync(path.join(__dirname, 'package', 'esm', 'light', `${filename || name}.js`), babel.transform(code, {
Expand Down
1 change: 0 additions & 1 deletion src/util/createIcon.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
"use client";
import { createSvgIcon } from "@mui/material/utils";

export default (path, name) => createSvgIcon(<path d={path} />, name);

0 comments on commit e1d02a5

Please sign in to comment.