From f78763de79648b8f64cef51c7bf2460f2b34290a Mon Sep 17 00:00:00 2001 From: Anna Date: Sat, 7 Nov 2026 13:39:49 +0300 Subject: [PATCH 1/7] Add quickstart guide --- src/content/blog/quickstart.md | 146 +++++++++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 src/content/blog/quickstart.md diff --git a/src/content/blog/quickstart.md b/src/content/blog/quickstart.md new file mode 100644 index 0000000..a1c6c90 --- /dev/null +++ b/src/content/blog/quickstart.md @@ -0,0 +1,146 @@ +--- + +title: "Quickstart: Build your first sprite in 5 minutes" +description: A quick introduction to svgforge that helps you install the tool, create your first sprite, and see how to use icons from the sprite in your own product. +pubDate: 2026-11-07 +tags: + +- tutorial +- svg + +--- + +In this guide, we'll build a **symbol sprite** and test its icons on a page using `` — the most modern and widely used approach. + +svgforge also supports other sprite modes: `view`, `stack`, and `defs`. For details, see [Specific mode properties](https://github.com/svgforge/svgforge/blob/main/docs/configuration.md#specific-mode-properties). + +## Prerequisites + +- Node.js 24 or later + +## Setup + +1. Create a project folder to work in. Let's call it `svgforge-project`. +2. Download a few SVG icons into that folder. +3. Install the library: + +```bash +npm install @svgforge/svgforge +``` + +You should see output similar to this in the terminal: + +``` +added 38 packages in 1m + +12 packages are looking for funding + run `npm fund` for details +``` + +## Building the sprite + +1. Create an `.mjs` file in the project folder (for example, `build-sprite.mjs`) and paste in the following code: + +```js +import fs from "node:fs"; +import path from "node:path"; +import SVGSpriter from "@svgforge/svgforge"; + +const config = { + dest: "out-lib", + mode: { + symbol: { + example: true, + }, + }, +}; + +const spriter = new SVGSpriter(config); + +for (const file of fs.globSync("*.svg")) { + spriter.add(file, null, fs.readFileSync(file, "utf8")); +} + +const { result } = await spriter.compileAsync(); + +for (const mode of Object.values(result)) { + for (const resource of Object.values(mode)) { + fs.mkdirSync(path.dirname(resource.path), { recursive: true }); + fs.writeFileSync(resource.path, resource.contents); + } +} +``` + +Save the file. + +2. Run it in the terminal: + +```bash +node build-sprite.mjs +``` + +Two files will appear in the `out-lib/symbol/` folder: + +- `sprite.symbol.svg` — the sprite itself +- `sprite.symbol.html` — a preview page (generated because of `example: true`) + +## Checking the sprite + +1. Start a local server: + +```bash +npx serve out-lib +``` + +2. Open in your browser: + +``` +http://localhost:3000/symbol/sprite.symbol.html +``` + +You should see a confirmation that the sprite is ready. Now the icons from the sprite can be used on any page via ``. + +## Using the sprite + +1. Create an HTML file inside the `out-lib/symbol/` folder. Name it `test-use.html`. + +2. Paste the following code into the file: + +```html + + + +``` + +`#home` is the icon's identifier in the symbol sprite. By default, it matches the original SVG file name without the extension: `home.svg` → `home`. + +**How to find your icon's identifier:** + +- Open the preview page: `http://localhost:3000/symbol/sprite.symbol.html` +- Find the icon you need. +- Click the **Copy ID** button next to it — the identifier will be copied to your clipboard. +- Paste it in place of `home` in ``. + +Save the file. + +3. If you stopped the local server earlier, start it again: + +```bash +npx serve out-lib +``` + +If the local server is still running, move on to the next step. + +4. Open in your browser: + +``` +http://localhost:3000/symbol/test-use.html +``` + +The browser should display the icon whose identifier you specified in ``. + +## Learn more + +- [Using symbol sprites via ``](https://github.com/svgforge/svgforge/blob/main/docs/configuration.md#defs--symbol-mode) +- [Other sprite modes: `view`, `stack`, `defs`](https://github.com/svgforge/svgforge/blob/main/docs/configuration.md#specific-mode-properties) +- [Full sprite configuration documentation](https://github.com/svgforge/svgforge/blob/main/docs/configuration.md) From b470b7815a5610affb7bf0590ca34567a7a15c68 Mon Sep 17 00:00:00 2001 From: Anna Date: Mon, 9 Nov 2026 12:39:30 +0300 Subject: [PATCH 2/7] Add CLI quickstart and unify quickstart step formatting --- src/content/blog/quickstart-cli.md | 130 +++++++++++++++++++++++++++++ src/content/blog/quickstart.md | 32 +++---- 2 files changed, 143 insertions(+), 19 deletions(-) create mode 100644 src/content/blog/quickstart-cli.md diff --git a/src/content/blog/quickstart-cli.md b/src/content/blog/quickstart-cli.md new file mode 100644 index 0000000..42a1701 --- /dev/null +++ b/src/content/blog/quickstart-cli.md @@ -0,0 +1,130 @@ +--- + +title: "Quickstart: Get started with the svgforge CLI in 5 minutes" +description: A quick introduction to the svgforge CLI that helps you install the tool, create your first sprite, and see how to use icons from the sprite in your own product. +pubDate: 2026-11-07 +tags: + +- tutorial +- svg + +--- + +In this guide, we'll build a **symbol sprite** using the command line and test its icons on a page via `` — the most modern and widely used approach. + +svgforge also supports other sprite modes: `view`, `stack`, and `defs`. For details, see [Specific mode properties](https://github.com/svgforge/svgforge/blob/main/docs/configuration.md#specific-mode-properties). + +## Prerequisites + +Node.js 24 or later + +## Setup + +**1.** Create a project folder to work in. Let's call it `svgforge-test`: + +```bash +mkdir svgforge-test +cd svgforge-test +``` + +**2.** Install the svgforge CLI + +```bash +npm install --global @svgforge/svgforge-cli +``` + +You should see output similar to this: + +```text +added 54 packages in 48s +... +``` + +**3.** Verify the installation: + +```bash +svgforge --help +``` + +If you see the list of commands, the CLI is installed correctly. + +## Building the sprite + +**1.** Add a few SVG icons to the `svgforge-test` folder. + +**2.** Run the following command in the terminal: + +```bash +svgforge --symbol --symbol-render-css --symbol-example --dest=out *.svg +``` + +This command: + +- `--symbol` — selects the `symbol` mode (the most popular one for icons) +- `--symbol-render-css` — creates a CSS file +- `--symbol-example` — creates an HTML page with an example +- `--dest=out` — puts everything into the `out` folder +- `*.svg` — takes all SVG files from the current folder + +If the `out` folder appears with the generated files, everything is working — you've just built your first sprite. + +## Checking the sprite + +**1.** Open the `out/symbol` folder. Inside, you should find the following files: + +- `symbol/svg/sprite.symbol.svg` +- `symbol/sprite.css` +- `symbol/sprite.symbol.html` + +**2.** Open `sprite.symbol.html` by double-clicking it, or right-click → **Open with** → your browser. A page with the icons from the sprite should open. + +If you can see the icons, everything is working perfectly and you can move on. + +If the page is empty or the icons are not displayed, your browser may be blocking external SVG references when the page is opened directly. In that case, serve the folder locally: + +```bash +npx serve out/symbol +``` + +Open the following URL in your browser: + +```text +http://localhost:3000/sprite.symbol.html +``` + +## Using the sprite + +Now the icons from the sprite can be used on any HTML page via ``. + +**1.** Create a file named `test-use.html` inside the `out/symbol` folder. + +**2.** Paste the following code into the file: + +```html + + + +``` + +`#home` is the icon's identifier in the symbol sprite. By default, it matches the original SVG file name without the extension: `home.svg` → `home`. + +**To find your icon's identifier:** + +- Open the preview page: `http://localhost:3000/sprite.symbol.html` +- Find the icon you need. +- Click the **Copy ID** button next to it — the identifier will be copied to your clipboard. +- Paste it in place of `home` in ``. + +**3.** If the local server is not running, restart it. Then open the following URL in your browser: + +```text +http://localhost:3000/test-use.html +``` + +The browser should display the icon whose identifier you specified in ``. + +## Learn more + +- [SVG sprite modes](https://github.com/svgforge/svgforge#output-modes) +- [Command-line reference](https://github.com/svgforge/svgforge-cli/blob/main/docs/command-line.md) +- [Configuration reference](https://github.com/svgforge/svgforge/blob/main/docs/configuration.md) diff --git a/src/content/blog/quickstart.md b/src/content/blog/quickstart.md index a1c6c90..fbb013b 100644 --- a/src/content/blog/quickstart.md +++ b/src/content/blog/quickstart.md @@ -16,13 +16,15 @@ svgforge also supports other sprite modes: `view`, `stack`, and `defs`. For deta ## Prerequisites -- Node.js 24 or later +Node.js 24 or later ## Setup -1. Create a project folder to work in. Let's call it `svgforge-project`. -2. Download a few SVG icons into that folder. -3. Install the library: +**1.** Create a project folder to work in. Let's call it `svgforge-project`. + +**2.** Download a few SVG icons into that folder. + +**3.** Install the library: ```bash npm install @svgforge/svgforge @@ -39,7 +41,7 @@ added 38 packages in 1m ## Building the sprite -1. Create an `.mjs` file in the project folder (for example, `build-sprite.mjs`) and paste in the following code: +**1.** Create an `.mjs` file in the project folder (for example, `build-sprite.mjs`) and paste in the following code: ```js import fs from "node:fs"; @@ -73,7 +75,7 @@ for (const mode of Object.values(result)) { Save the file. -2. Run it in the terminal: +**2.** Run it in the terminal: ```bash node build-sprite.mjs @@ -86,13 +88,13 @@ Two files will appear in the `out-lib/symbol/` folder: ## Checking the sprite -1. Start a local server: +**1.** Start a local server: ```bash npx serve out-lib ``` -2. Open in your browser: +**2.** Open in your browser: ``` http://localhost:3000/symbol/sprite.symbol.html @@ -102,9 +104,9 @@ You should see a confirmation that the sprite is ready. Now the icons from the s ## Using the sprite -1. Create an HTML file inside the `out-lib/symbol/` folder. Name it `test-use.html`. +**1.** Create an HTML file inside the `out-lib/symbol/` folder. Name it `test-use.html`. -2. Paste the following code into the file: +**2.** Paste the following code into the file: ```html @@ -123,15 +125,7 @@ You should see a confirmation that the sprite is ready. Now the icons from the s Save the file. -3. If you stopped the local server earlier, start it again: - -```bash -npx serve out-lib -``` - -If the local server is still running, move on to the next step. - -4. Open in your browser: +**3.** If the local server is not running, restart it. Then open in your browser: ``` http://localhost:3000/symbol/test-use.html From 5669f9bb06c33d74e9bfd71e58368635c24e6faa Mon Sep 17 00:00:00 2001 From: Anna Date: Wed, 11 Nov 2026 13:47:31 +0300 Subject: [PATCH 3/7] Update CLI quickstart and JS quickstart --- src/content/blog/quickstart-cli.md | 10 ++++++---- src/content/blog/quickstart.md | 4 +++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/content/blog/quickstart-cli.md b/src/content/blog/quickstart-cli.md index 42a1701..f54cadd 100644 --- a/src/content/blog/quickstart-cli.md +++ b/src/content/blog/quickstart-cli.md @@ -10,7 +10,7 @@ tags: --- -In this guide, we'll build a **symbol sprite** using the command line and test its icons on a page via `` — the most modern and widely used approach. +In this guide, we'll build a **symbol sprite** using the command line and test its icons on a page via ``. svgforge also supports other sprite modes: `view`, `stack`, and `defs`. For details, see [Specific mode properties](https://github.com/svgforge/svgforge/blob/main/docs/configuration.md#specific-mode-properties). @@ -72,9 +72,9 @@ If the `out` folder appears with the generated files, everything is working — **1.** Open the `out/symbol` folder. Inside, you should find the following files: -- `symbol/svg/sprite.symbol.svg` -- `symbol/sprite.css` -- `symbol/sprite.symbol.html` +- `svg/sprite.symbol.svg` +- `sprite.css` +- `sprite.symbol.html` **2.** Open `sprite.symbol.html` by double-clicking it, or right-click → **Open with** → your browser. A page with the icons from the sprite should open. @@ -108,6 +108,8 @@ Now the icons from the sprite can be used on any HTML page via ``. `#home` is the icon's identifier in the symbol sprite. By default, it matches the original SVG file name without the extension: `home.svg` → `home`. +Replace `home` with the ID of the icon you want to use. + **To find your icon's identifier:** - Open the preview page: `http://localhost:3000/sprite.symbol.html` diff --git a/src/content/blog/quickstart.md b/src/content/blog/quickstart.md index fbb013b..38eb145 100644 --- a/src/content/blog/quickstart.md +++ b/src/content/blog/quickstart.md @@ -10,7 +10,7 @@ tags: --- -In this guide, we'll build a **symbol sprite** and test its icons on a page using `` — the most modern and widely used approach. +In this guide, we'll build a **symbol sprite** and test its icons on a page using ``. svgforge also supports other sprite modes: `view`, `stack`, and `defs`. For details, see [Specific mode properties](https://github.com/svgforge/svgforge/blob/main/docs/configuration.md#specific-mode-properties). @@ -116,6 +116,8 @@ You should see a confirmation that the sprite is ready. Now the icons from the s `#home` is the icon's identifier in the symbol sprite. By default, it matches the original SVG file name without the extension: `home.svg` → `home`. +Replace `home` with the ID of the icon you want to use. + **How to find your icon's identifier:** - Open the preview page: `http://localhost:3000/symbol/sprite.symbol.html` From 43f1b88ab5274ad26eff961a950ce2786bd471d1 Mon Sep 17 00:00:00 2001 From: Anna Date: Thu, 12 Nov 2026 12:33:29 +0300 Subject: [PATCH 4/7] fix text --- src/content/blog/quickstart.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/blog/quickstart.md b/src/content/blog/quickstart.md index 38eb145..79f3a4c 100644 --- a/src/content/blog/quickstart.md +++ b/src/content/blog/quickstart.md @@ -24,7 +24,7 @@ Node.js 24 or later **2.** Download a few SVG icons into that folder. -**3.** Install the library: +**3.** Install the svgforge: ```bash npm install @svgforge/svgforge From 102dc68b9f4a9c93bbb939d89d4fc6accee9dc7f Mon Sep 17 00:00:00 2001 From: Anna Date: Thu, 12 Nov 2026 13:01:53 +0300 Subject: [PATCH 5/7] add draft: true --- src/content/blog/quickstart-cli.md | 1 + src/content/blog/quickstart.md | 1 + 2 files changed, 2 insertions(+) diff --git a/src/content/blog/quickstart-cli.md b/src/content/blog/quickstart-cli.md index f54cadd..883860e 100644 --- a/src/content/blog/quickstart-cli.md +++ b/src/content/blog/quickstart-cli.md @@ -3,6 +3,7 @@ title: "Quickstart: Get started with the svgforge CLI in 5 minutes" description: A quick introduction to the svgforge CLI that helps you install the tool, create your first sprite, and see how to use icons from the sprite in your own product. pubDate: 2026-11-07 +draft: true tags: - tutorial diff --git a/src/content/blog/quickstart.md b/src/content/blog/quickstart.md index 79f3a4c..ece3b8d 100644 --- a/src/content/blog/quickstart.md +++ b/src/content/blog/quickstart.md @@ -3,6 +3,7 @@ title: "Quickstart: Build your first sprite in 5 minutes" description: A quick introduction to svgforge that helps you install the tool, create your first sprite, and see how to use icons from the sprite in your own product. pubDate: 2026-11-07 +draft: true tags: - tutorial From be448987ae5a800d6cc4ed4b80bc6e31e56b1ed7 Mon Sep 17 00:00:00 2001 From: Anna Date: Fri, 20 Nov 2026 15:01:15 +0300 Subject: [PATCH 6/7] Improve Node.js Quickstart instructions Clarify script configuration, icon file paths, output directory and execution steps to help users adapt the example to their projects. --- src/content/blog/quickstart.md | 36 +++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/src/content/blog/quickstart.md b/src/content/blog/quickstart.md index ece3b8d..a904903 100644 --- a/src/content/blog/quickstart.md +++ b/src/content/blog/quickstart.md @@ -74,23 +74,49 @@ for (const mode of Object.values(result)) { } ``` +This script uses svgforge to combine SVG icons from your project into a single **symbol sprite** and saves the generated files to the `out-lib` directory. + +- `dest: "out-lib"` sets the output directory where the generated files are written. + + In this example, the generated files are written to the `out-lib` directory in the root of your `svgforge-project` folder. + + If you're using svgforge in an existing project, set `dest` to the directory where you want the generated files to be written. For example, this could be `dist` or `public`, depending on your project's structure and build setup. + + `` is the directory you set in `dest`. + +- `fs.globSync("*.svg")` finds SVG files matching the specified glob pattern. + Replace `*.svg` with the path to your icon directory. For example, `src/assets/icons/**/*.svg` matches SVG files in the `src/assets/icons` directory and all its subdirectories. + Save the file. -**2.** Run it in the terminal: +**2.** Run the `.mjs` file in the terminal: ```bash node build-sprite.mjs ``` -Two files will appear in the `out-lib/symbol/` folder: +If you named the file differently in the previous step, replace `build-sprite.mjs` with your file name. For example, if you created `icons.mjs`, run: + +```bash +node icons.mjs +``` + +Two files will appear in the `/symbol/` folder: - `sprite.symbol.svg` — the sprite itself - `sprite.symbol.html` — a preview page (generated because of `example: true`) +If you set `dest: "out-lib"`, the files will appear in the `out-lib/symbol/` folder. + ## Checking the sprite **1.** Start a local server: +```bash +npx serve +``` +If you set `dest: "out-lib"`, run: + ```bash npx serve out-lib ``` @@ -101,11 +127,15 @@ npx serve out-lib http://localhost:3000/symbol/sprite.symbol.html ``` +If the terminal shows a different port, use that port in the URL. + You should see a confirmation that the sprite is ready. Now the icons from the sprite can be used on any page via ``. ## Using the sprite -**1.** Create an HTML file inside the `out-lib/symbol/` folder. Name it `test-use.html`. +**1.** Create an HTML file inside the `/symbol/` folder. In this example — `out-lib/symbol/`. + +Name it `test-use.html`. **2.** Paste the following code into the file: From 4a23e1c9c5dbb258c10b6efbb43790ccd386b789 Mon Sep 17 00:00:00 2001 From: Anna Date: Sun, 22 Nov 2026 12:28:59 +0300 Subject: [PATCH 7/7] docs: improve CLI quickstart project setup and usage --- src/content/blog/quickstart-cli.md | 48 ++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/src/content/blog/quickstart-cli.md b/src/content/blog/quickstart-cli.md index 883860e..03c8358 100644 --- a/src/content/blog/quickstart-cli.md +++ b/src/content/blog/quickstart-cli.md @@ -51,7 +51,7 @@ If you see the list of commands, the CLI is installed correctly. ## Building the sprite -**1.** Add a few SVG icons to the `svgforge-test` folder. +**1.** Add a few SVG icons to the `svgforge-test` folder. If you want to use icons from another folder, specify its path in the build command below. **2.** Run the following command in the terminal: @@ -61,21 +61,43 @@ svgforge --symbol --symbol-render-css --symbol-example --dest=out *.svg This command: -- `--symbol` — selects the `symbol` mode (the most popular one for icons) +- `--symbol` — selects the `symbol` mode - `--symbol-render-css` — creates a CSS file - `--symbol-example` — creates an HTML page with an example -- `--dest=out` — puts everything into the `out` folder +- `--dest=out` — sets the main output directory - `*.svg` — takes all SVG files from the current folder -If the `out` folder appears with the generated files, everything is working — you've just built your first sprite. +To adapt the command to your project, you only need to change two parameters: + +- `--dest=out` + + In this example, svgforge writes the generated files to the out folder. + + If you're using svgforge in an existing project, set `--dest` to the directory where you want the generated files to be written. + + For example, this could be `dist` or `public`, depending on your project's structure and build setup. + + `` is the directory you set in `--dest`. The generated files for the symbol mode are placed in the symbol subdirectory. + +- `*.svg`. + + If you want to work with icons in an existing project, replace `*.svg` with a glob pattern that matches the location of your own icons. + + For example, `src/assets/icons/**/*.svg` matches SVG files in the src/assets/icons directory and all its subdirectories. + + ```bash + svgforge --symbol --symbol-render-css --symbol-example --dest= 'src/assets/icons/**/*.svg' + ``` + +If the output folder contains the generated files, everything is working — you've just built your first sprite. If you specified a directory other than out in --dest, look for the generated files there. ## Checking the sprite -**1.** Open the `out/symbol` folder. Inside, you should find the following files: +**1.** Open the `out` folder or another folder you set in `--dest`. Inside, you should find the following files: -- `svg/sprite.symbol.svg` -- `sprite.css` -- `sprite.symbol.html` +- `symbol/svg/sprite.symbol.svg` +- `symbol/sprite.css` +- `symbol/sprite.symbol.html` **2.** Open `sprite.symbol.html` by double-clicking it, or right-click → **Open with** → your browser. A page with the icons from the sprite should open. @@ -84,10 +106,12 @@ If you can see the icons, everything is working perfectly and you can move on. If the page is empty or the icons are not displayed, your browser may be blocking external SVG references when the page is opened directly. In that case, serve the folder locally: ```bash -npx serve out/symbol +npx serve /symbol ``` -Open the following URL in your browser: +In this example, the symbol output folder is `out/symbol`. + +Now open the link shown in the terminal in your browser. It will look something like this: ```text http://localhost:3000/sprite.symbol.html @@ -97,7 +121,7 @@ http://localhost:3000/sprite.symbol.html Now the icons from the sprite can be used on any HTML page via ``. -**1.** Create a file named `test-use.html` inside the `out/symbol` folder. +**1.** Create a file named `test-use.html` inside the `out/symbol` folder or another symbol output folder you set in `--dest`. **2.** Paste the following code into the file: @@ -118,7 +142,7 @@ Replace `home` with the ID of the icon you want to use. - Click the **Copy ID** button next to it — the identifier will be copied to your clipboard. - Paste it in place of `home` in ``. -**3.** If the local server is not running, restart it. Then open the following URL in your browser: +**3.** If the local server is not running, restart it. Then open the `test-use.html` page in your browser. It will be available at a URL like: ```text http://localhost:3000/test-use.html