-
-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: icons tree-shaking for prod and pre-bundling for dev
- Loading branch information
1 parent
736a059
commit 07dc938
Showing
12 changed files
with
52 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
//@ts-ignore | ||
import SVGFixer from 'oslllo-svg-fixer'; | ||
import SVGFixer from 'oslllo-svg-fixer' | ||
|
||
const searchDir = "node_modules/lucide-static/icons/"; | ||
const outDir = "./icons/" | ||
const searchDir = 'node_modules/lucide-static/icons/' | ||
const outDir = './icons/' | ||
|
||
async function main() { | ||
await SVGFixer(searchDir, outDir).fix() | ||
} | ||
|
||
main(); | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,40 @@ | ||
import { readdir, readFile, writeFile } from "fs/promises"; | ||
import { readdir, readFile, writeFile } from 'fs/promises' | ||
|
||
const baseDir = "icons/"; | ||
const baseDir = 'icons/' | ||
|
||
async function main() { | ||
const icons = await readdir(baseDir); | ||
const icons = await readdir(baseDir) | ||
for (const icon of icons) { | ||
if (icon === ".gitkeep") { | ||
continue; | ||
if (icon === '.gitkeep') { | ||
continue | ||
} | ||
const name = getName(icon); | ||
const raw = await readFile(`${baseDir}${icon}`); | ||
const svg = raw.toString(); | ||
const name = getName(icon) | ||
const raw = await readFile(`${baseDir}${icon}`) | ||
const svg = raw.toString() | ||
const code = ` | ||
/* eslint-disable no-shadow-restricted-names */ | ||
import { SvgIconFromText, ComponentInternals } from "@react-three/uikit"; | ||
import { ComponentPropsWithoutRef, forwardRef } from "react"; | ||
export type ${name}Props = Omit<ComponentPropsWithoutRef<typeof SvgIconFromText>, "text" | "svgWidth" | "svgHeight">; | ||
const text = \`${svg}\`; | ||
export const ${name} = forwardRef<ComponentInternals, ${name}Props>((props, ref) => { | ||
export const ${name} = /*@__PURE__*/ forwardRef<ComponentInternals, ${name}Props>((props, ref) => { | ||
return <SvgIconFromText {...props} ref={ref} text={text} svgWidth={24} svgHeight={24} /> | ||
}) | ||
`; | ||
writeFile(`src/${name}.tsx`, code); | ||
` | ||
writeFile(`src/${name}.tsx`, code) | ||
} | ||
writeFile( | ||
"src/index.tsx", | ||
icons.filter(icon => icon != ".gitkeep").map((icon) => `export * from "./${getName(icon)}.js";`).join("\n"), | ||
); | ||
'src/index.tsx', | ||
icons | ||
.filter((icon) => icon != '.gitkeep') | ||
.map((icon) => `export * from "./${getName(icon)}.js";`) | ||
.join('\n'), | ||
) | ||
} | ||
|
||
function getName(file: string): string { | ||
const name = file.slice(0, -4); | ||
return name[0].toUpperCase() + name.slice(1).replace(/-./g, (x) => x[1].toUpperCase()); | ||
const name = file.slice(0, -4) | ||
return name[0].toUpperCase() + name.slice(1).replace(/-./g, (x) => x[1].toUpperCase()) | ||
} | ||
|
||
main(); | ||
main() |
Empty file.