SVGER-CLI Build Tool Integrations

November 26, 2025 ยท View on GitHub

Official build tool integrations for SVGER-CLI, providing seamless SVG to component conversion in your existing build pipeline.

๐Ÿš€ Quick Start

npm install svger-cli --save-dev

๐Ÿ“ฆ Available Integrations

  • Webpack - Plugin & Loader with HMR
  • Vite - Plugin with HMR & Virtual Modules
  • Rollup - Plugin with Tree-Shaking
  • Babel - Plugin with Import Transformation
  • Next.js - Wrapper with SSR Support
  • Jest - Preset & Transformer

Webpack Integration

Installation

npm install svger-cli --save-dev

Usage

webpack.config.js:

const { SvgerWebpackPlugin } = require('svger-cli/webpack');

module.exports = {
  plugins: [
    new SvgerWebpackPlugin({
      source: './src/icons',
      output: './src/components/icons',
      framework: 'react',
      typescript: true,
      hmr: true,
      generateIndex: true,
    }),
  ],

  module: {
    rules: [
      {
        test: /\.svg$/,
        use: [
          {
            loader: 'svger-cli/webpack-loader',
            options: {
              framework: 'react',
              typescript: true,
            },
          },
        ],
      },
    ],
  },
};

Options

OptionTypeDefaultDescription
sourcestring'./src/icons'Source directory containing SVG files
outputstring'./src/components/icons'Output directory for generated components
frameworkstring'react'Target framework (react, vue, angular, etc.)
typescriptbooleantrueGenerate TypeScript files
hmrbooleantrueEnable Hot Module Replacement
generateIndexbooleantrueGenerate index file with exports

See full example โ†’


Vite Integration

Installation

npm install svger-cli --save-dev

Usage

vite.config.js:

import { svgerVitePlugin } from 'svger-cli/vite';

export default {
  plugins: [
    svgerVitePlugin({
      source: './src/icons',
      output: './src/components/icons',
      framework: 'react',
      typescript: true,
      hmr: true,
    }),
  ],
};

Options

OptionTypeDefaultDescription
sourcestring'./src/icons'Source directory containing SVG files
outputstring'./src/components/icons'Output directory for generated components
frameworkstring'react'Target framework
typescriptbooleantrueGenerate TypeScript files
hmrbooleantrueEnable Hot Module Replacement
virtualbooleanfalseUse virtual modules
exportTypestring'default'Export type ('default' or 'named')

See full example โ†’


Rollup Integration

Installation

npm install svger-cli --save-dev

Usage

rollup.config.js:

import { svgerRollupPlugin } from 'svger-cli/rollup';

export default {
  plugins: [
    svgerRollupPlugin({
      source: './src/icons',
      output: './src/components/icons',
      framework: 'react',
      typescript: true,
      sourcemap: true,
    }),
  ],
};

Options

OptionTypeDefaultDescription
sourcestring'./src/icons'Source directory containing SVG files
outputstring'./src/components/icons'Output directory for generated components
frameworkstring'react'Target framework
typescriptbooleantrueGenerate TypeScript files
sourcemapbooleanfalseGenerate source maps
exportTypestring'default'Export type ('default' or 'named')

See full example โ†’


Babel Integration

Installation

npm install svger-cli --save-dev

Usage

babel.config.js:

const { svgerBabelPlugin } = require('svger-cli/babel');

module.exports = {
  presets: ['@babel/preset-env', '@babel/preset-react'],
  plugins: [
    [
      svgerBabelPlugin,
      {
        source: './src/icons',
        output: './src/components/icons',
        framework: 'react',
        typescript: true,
        transformImports: true,
        processOnInit: true,
        generateIndex: true,
      },
    ],
  ],
};

Or with ES Modules (babel.config.mjs):

import { svgerBabelPlugin } from 'svger-cli/babel';

export default {
  presets: ['@babel/preset-react'],
  plugins: [
    [
      svgerBabelPlugin,
      {
        source: './src/icons',
        output: './src/components/icons',
        framework: 'react',
      },
    ],
  ],
};

Features

  • โœ… Import Transformation - Automatically transforms SVG imports to component imports
  • โœ… Dynamic Imports - Supports import('./icon.svg') syntax
  • โœ… Auto-Processing - Processes all SVGs when plugin initializes
  • โœ… Framework Agnostic - Works with any Babel-based setup
  • โœ… TypeScript Support - Full type definitions included

How It Works

// Before transformation
import HomeIcon from './assets/home.svg';

// After transformation (automatic)
import HomeIcon from './components/icons/HomeIcon';

// Use in your component
function App() {
  return <HomeIcon width={24} height={24} />;
}

Options

OptionTypeDefaultDescription
sourcestring'./src/icons'Source directory containing SVG files
outputstring'./src/components/icons'Output directory for generated components
frameworkstring'react'Target framework (react, vue, angular, etc.)
typescriptbooleantrueGenerate TypeScript files
transformImportsbooleantrueTransform SVG imports to component imports
processOnInitbooleantrueProcess all SVGs when plugin initializes
generateIndexbooleantrueGenerate index file with all exports
includearray['**/*.svg']Glob patterns to include
excludearray['node_modules/**']Glob patterns to exclude

Use Cases

Create React App:

// babel-plugin-macros.config.js
const { createBabelPlugin } = require('svger-cli/babel');

module.exports = {
  svger: createBabelPlugin({
    source: './src/icons',
    framework: 'react',
  }),
};

Gatsby:

// gatsby-config.js
module.exports = {
  plugins: [
    {
      resolve: 'gatsby-plugin-babel-plugin-svger',
      options: {
        source: './src/assets/icons',
        framework: 'react',
      },
    },
  ],
};

Vue CLI:

// babel.config.js
const { svgerBabelPlugin } = require('svger-cli/babel');

module.exports = {
  presets: ['@vue/cli-plugin-babel/preset'],
  plugins: [
    [
      svgerBabelPlugin,
      {
        source: './src/assets/icons',
        framework: 'vue',
      },
    ],
  ],
};

See full example โ†’


Next.js Integration

Installation

npm install svger-cli --save-dev

Usage

next.config.js:

const { withSvger } = require('svger-cli/nextjs');

module.exports = withSvger({
  svger: {
    source: './public/icons',
    output: './components/icons',
    framework: 'react',
    typescript: true,
    ssr: true,
  },
  // ... other Next.js config
});

Options

OptionTypeDefaultDescription
sourcestring'./src/icons'Source directory containing SVG files
outputstring'./src/components/icons'Output directory for generated components
frameworkstring'react'Always 'react' for Next.js
typescriptbooleantrueGenerate TypeScript files
ssrbooleantrueEnable Server-Side Rendering support
hmrbooleantrueEnable Hot Module Replacement

See full example โ†’


Jest Integration

Installation

npm install svger-cli --save-dev

Usage

jest.config.js:

module.exports = {
  preset: 'svger-cli/jest',
  testEnvironment: 'jsdom',
};

Or manually:

module.exports = {
  transform: {
    '\\.svg$': 'svger-cli/jest-transformer',
  },
};

Options

Configure through transformer config:

transform: {
  '\\.svg$': ['svger-cli/jest-transformer', {
    framework: 'react',
    typescript: true,
    mock: false,  // Use simple mocks for faster tests
  }],
}

See full example โ†’


๐ŸŽฏ Usage Examples

React Component

import { StarIcon, MenuIcon } from './components/icons';

function App() {
  return (
    <div>
      <StarIcon width={24} height={24} fill="gold" />
      <MenuIcon />
    </div>
  );
}

Vue Component

<template>
  <div>
    <StarIcon :width="24" :height="24" fill="gold" />
  </div>
</template>

<script setup>
import { StarIcon } from './components/icons';
</script>

Angular Component

import { Component } from '@angular/core';
import { StarIconComponent } from './components/icons';

@Component({
  selector: 'app-root',
  template: ` <app-star-icon [width]="24" [height]="24" fill="gold"></app-star-icon> `,
  standalone: true,
  imports: [StarIconComponent],
})
export class AppComponent {}

๐Ÿ”ง Supported Frameworks

All integrations support these frameworks:

  • โœ… React
  • โœ… React Native
  • โœ… Vue 3 (Composition & Options API)
  • โœ… Angular (Standalone & Module)
  • โœ… Svelte
  • โœ… Solid
  • โœ… Preact
  • โœ… Lit
  • โœ… Vanilla JS/TS

๐Ÿ“š Complete Examples

Explore full working examples in the examples/ directory:


๐Ÿš€ Features

All Integrations Include:

  • โœ… Zero Dependencies - No bloat
  • โœ… TypeScript Support - Full type safety
  • โœ… Framework Agnostic - Works with all major frameworks
  • โœ… Tree Shaking - Bundle only what you use
  • โœ… Auto-Generated Exports - Convenient barrel files
  • โœ… 85% Faster - Than alternatives like SVGR

Build Tool Specific:

FeatureWebpackViteRollupBabelNext.jsJest
HMR Supportโœ…โœ…โŒโŒโœ…N/A
Source Mapsโœ…โœ…โœ…โŒโœ…โŒ
SSR SupportโŒโœ…โŒโŒโœ…N/A
Virtual ModulesโŒโœ…โŒโŒโŒN/A
Watch Modeโœ…โœ…โœ…โœ…โœ…N/A
Import Transformโœ…โœ…โœ…โœ…โœ…โœ…
Dynamic Importsโœ…โœ…โœ…โœ…โœ…โŒ
Framework Agnosticโœ…โœ…โœ…โœ…โŒโœ…

๐Ÿงช Testing

Run integration tests:

npm run test:integrations

All integrations are thoroughly tested and verified to work correctly.


๐Ÿ“– Documentation

For complete documentation, visit the main README or check out specific guides:


๐Ÿ’ฌ Support


๐Ÿ“„ License

MIT ยฉ SVGER-CLI Development Team