Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ import { NotificationIcon } from '@hugeicons/core-free-icons';
- **Tree-shaking**: The package is fully tree-shakeable, ensuring only the icons you use are included in your final bundle
- **Optimized SVGs**: All icons are optimized for size and performance
- **Code Splitting**: Icons can be easily code-split when using dynamic imports
- **Subpath imports**: `import SearchIcon from "@hugeicons/core-free-icons/SearchIcon"` loads one icon instead of the full barrel

## Troubleshooting

Expand All @@ -153,6 +154,7 @@ import { NotificationIcon } from '@hugeicons/core-free-icons';

3. **Bundle size concerns?**
- Use named imports instead of importing the entire icon set
- Use subpath imports (`import Icon from "@hugeicons/core-free-icons/Icon"`) to cut dev-bundle size
- Add code splitting for different sections of your app
- Verify your bundler is configured to tree shake ESM builds

Expand Down
19 changes: 17 additions & 2 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import terser from '@rollup/plugin-terser';
import dts from 'rollup-plugin-dts';
import nodeResolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import { writeFileSync, mkdirSync } from 'fs';
import { copyFileSync, readFileSync, writeFileSync, mkdirSync } from 'fs';

// Plugin to generate package.json with "type": "module" for ESM build
const generateEsmPackageJson = () => ({
Expand All @@ -16,6 +16,21 @@ const generateEsmPackageJson = () => ({
}
});

// Plugin to copy ambient .d.ts files and reference them from the entry
const copyAmbientTypes = () => ({
name: 'copy-ambient-types',
writeBundle(options) {
if (options.dir && options.dir.includes('types')) {
copyFileSync('src/core-free-icons.d.ts', `${options.dir}/core-free-icons.d.ts`);
const indexPath = `${options.dir}/index.d.ts`;
const content = readFileSync(indexPath, 'utf8');
if (!content.startsWith('/// <reference path=')) {
writeFileSync(indexPath, `/// <reference path="./core-free-icons.d.ts" />\n${content}`);
}
}
}
});

const input = 'src/index.ts';
const external = id => /^react($|\/)/.test(id);
const globals = {
Expand Down Expand Up @@ -105,6 +120,6 @@ export default defineConfig([
preserveModulesRoot: 'src'
},
external,
plugins: [dts()]
plugins: [dts(), copyAmbientTypes()]
}
]);
6 changes: 6 additions & 0 deletions src/core-free-icons.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
declare module '@hugeicons/core-free-icons/*' {
const icon:
| [string, { [key: string]: string | number }][]
| readonly (readonly [string, { readonly [key: string]: string | number }])[];
export default icon;
}
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/// <reference path="./core-free-icons.d.ts" />

export { default as HugeiconsIcon } from './HugeiconsIcon';
export type { HugeiconsIconProps, HugeiconsProps, IconSvgElement } from './HugeiconsIcon';
export type { HugeiconsIconProps, HugeiconsProps, IconSvgElement } from './HugeiconsIcon';