svg-to-ts is a build tool that converts SVG icons into TypeScript or TSX files, facilitating the creation of tree-shakable icon libraries. It processes SVG files, applies optional SVGO optimization, and generates various output formats: a single TypeScript file exporting a constants object, multiple individual named constant exports, or separate files for each icon, optimized for lazy loading. It also automatically generates corresponding TypeScript types and interfaces for the icon sets. The current stable version is 12.0.0. The project maintains a consistent release cadence, often introducing major versions annually driven by updates to underlying tools like SVGO or advancements in TypeScript language features. Its key differentiators include robust SVGO integration for automatic optimization, broad support for Angular, React, and vanilla TypeScript/JavaScript environments, and the flexibility to produce diverse output structures tailored to different application architectures and lazy-loading strategies. This makes it a versatile solution for authors of component and icon libraries, as well as single-page application developers.
npm install svg-to-tsVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to set up `svg-to-ts` in `package.json` to convert a sample SVG icon into a TypeScript constant, and how to import and use the generated output in an application.
Update your project's `typescript` dependency to version `3.8` or higher: `npm install typescript@^3.8` or `yarn add typescript@^3.8`.
Review all import statements for generated icon files. Change `.js` extensions to `.mjs` where applicable: `import { Icon } from './my-icon.mjs';`Consult the official SVGO v3 documentation for updated configuration schemas and adjust your `svgoConfig` property within the `svg-to-ts` configuration accordingly.
Utilize configuration options like `prefix`, `namePrefix`, `delimiter`, and `conversionCase` or leverage custom naming functions to ensure generated icon names are unique and follow your project's conventions.
Update your import paths to use the `.mjs` extension: `import { MyIcon } from './my-icon.mjs';`Review your `svgoConfig` object in the `svg-to-ts` configuration. Refer to the SVGO v3 documentation for the updated configuration syntax.
Upgrade your project's TypeScript dependency to version `3.8` or higher: `npm install typescript@^3.8`.
No dependency data recorded yet.