2.1.0 • Published 3 months ago

@ztrehagem/svg-bundler v2.1.0

Weekly downloads
-
License
Unlicense
Repository
github
Last release
3 months ago

@ztrehagem/svg-bundler

Latest Version Type Definitions License

Generating SVG sprite. Bundle SVGs into a single SVG as a collection of symbols, and generate manifest.

Features

Specified SVG files or strings are converted into <symbol> with id attribute, and bundled into single <svg>. Furthermore, a manifest JSON is generated that has id, width, height, and viewBox attributes of each SVG. Normally the parent of <use> is a <svg>, the manifest is useful for applying their attributes to the <svg>.

This library won't optimize SVGs like SVGO, just bundle.

Installation

npm install @ztrehagem/svg-bundler

Usage (CLI)

Note: Node.js >= 20.0.0 is required to use CLI.

npx @ztrehagem/svg-bundler --srcDir=./path/to/srcDir --outDir=./path/to/outDir
ArgumentTypeRequiredDefaultDescription
--srcDirstringPath to the directory that includes ".svg" files.
--outDirstringPath to the output directory.
--spriteFilenamestring"sprite.svg"Filename of the SVG sprite file.
--manifestFilenamestring"manifest.json"Filename of the manifest file.

Usage (JS API)

import { SvgBundler } from "@ztrehagem/svg-bundler";

const bundler = new SvgBundler();

bundler.add(
  "foo",
  '<svg width="24px" height="24px" viewBox="0 0 24 24">...</svg>',
);

const { bundled, manifest } = await bundler.bundle();

console.log(bundled);
// <svg width="0" height="0" style="display:none;">
//   <symbol id="foo" width="24px" height="24px" viewBox="0 0 24 24">
//   ...
//   </symbol>
// </svg>

console.log(manifest);
// {
//   foo: {
//     width: "24px",
//     height: "24px",
//     viewBox: "0 0 24 24"
//   }
// }
2.1.0

3 months ago

2.0.1

6 months ago

2.0.0

2 years ago

1.0.0

3 years ago