From a87ac013f7f42a0088fc1f2abd05c20e6cad05ce Mon Sep 17 00:00:00 2001 From: Karsa Date: Tue, 24 Jun 2025 13:18:07 +0200 Subject: [PATCH] docs(packages/lucide-static): update docs for better clarity (#3225) * docs(packages/lucide-static): update docs for better clarity * docs(packages/lucide-static): fix node.js heading level --- .../lib/codeExamples/createCodeExamples.ts | 12 +- docs/guide/packages/lucide-static.md | 172 ++++++++++++------ 2 files changed, 115 insertions(+), 69 deletions(-) diff --git a/docs/.vitepress/lib/codeExamples/createCodeExamples.ts b/docs/.vitepress/lib/codeExamples/createCodeExamples.ts index 7848841c2..0539dd37b 100644 --- a/docs/.vitepress/lib/codeExamples/createCodeExamples.ts +++ b/docs/.vitepress/lib/codeExamples/createCodeExamples.ts @@ -1,5 +1,4 @@ -import { bundledLanguages, type ThemeRegistration } from 'shikiji'; -import { getHighlighter } from 'shikiji'; +import { bundledLanguages, getHighlighter, type ThemeRegistration } from 'shikiji'; type CodeExampleType = { title: string; @@ -102,13 +101,8 @@ import { LucideAngularModule, $PascalCase } from 'lucide-angular'; }, { language: 'html', - title: 'Icon Font', - code: ` - -
-`, + title: 'Icon font', + code: `
`, }, ]; }; diff --git a/docs/guide/packages/lucide-static.md b/docs/guide/packages/lucide-static.md index 09f87abb5..da93aa81a 100644 --- a/docs/guide/packages/lucide-static.md +++ b/docs/guide/packages/lucide-static.md @@ -1,24 +1,38 @@ # Lucide Static -This package include the following lucide implementations: +This package includes the following implementations of Lucide icons: -- All SVG files +- Individual SVG files - SVG sprite -- Icon fonts -- JavaScript library containing strings of SVGs. +- Icon font files +- A JavaScript library exporting SVG strings -## Why lucide-static? +## Who is this for? -This package is suitable for specific use cases, for example if you want to use icon fonts, SVG sprites, normal SVGs or Common.js SVG strings in your javascript project. +`lucide-static` is suitable for _very specific use cases_ where you want to use Lucide icons without relying on a JavaScript framework or component system. It's ideal for: -::: warning -While they can be useful for prototyping, it is not recommended to use the SVG sprites or icon fonts provided by this package in production web apps as all the available icons are included in the app, hence increasing loading time and data usage. We recommend to use a bundler and tree-shaking to make sure only the icons you use are bundled with your app. Tree-shaking is only available in these packages: [lucide](lucide), [lucide-react](lucide-react), [lucide-vue](lucide-vue), [lucide-vue-next](lucide-vue-next), [lucide-angular](lucide-angular), [lucide-preact](lucide-preact) +- Projects that use icon fonts with plain CSS or utility-first frameworks +- Embedding raw SVG files or sprites directly in HTML +- Using SVGs as CSS background images +- Importing SVG strings into Node.js (CommonJS) environments + +::: danger +### Not recommended for production {#production-warning} + +SVG sprites and icon fonts include **all icons**, which can significantly increase your app's bundle size and load time. + +For production environments, we recommend using a bundler with tree-shaking support to include only the icons you actually use. Consider using: + +- [lucide](lucide) +- [lucide-react](lucide-react) +- [lucide-vue](lucide-vue) +- [lucide-vue-next](lucide-vue-next) +- [lucide-angular](lucide-angular) +- [lucide-preact](lucide-preact) ::: ## Installation -## Package Managers - ::: code-group ```sh [pnpm] @@ -39,64 +53,77 @@ bun add lucide-static ::: -### CDN +## SVG Files -```html - - +You can use standalone SVG files or SVG sprites in several ways. - - -``` +Check out our [codesandbox example](https://codesandbox.io/s/using-the-svg-sprite-lz1kk). -## Usage +### SVG file as image -Check out the [codesandbox examples](https://codesandbox.io/s/using-the-svg-sprite-lz1kk). +#### In HTML: -### SVG Files +::: code-group -#### SVG file as image - -To use it in for example html: - -```html +```html [Webpack] ``` -```css +```html [CDN] + + +``` + +::: + +#### In CSS: + +::: code-group + +```css [Webpack] .house-icon { background-image: url(~lucide-static/icons/house.svg); } ``` -Make sure you have the correct webpack loaders to make this work. [url-loader](https://v4.webpack.js.org/loaders/url-loader/) +```css [CDN] +.house-icon { + background-image: url(https://unpkg.com/lucide-static@latest/icons/house.svg); +} +``` -#### SVG file as string +::: -You can simply import each SVG by targeting `lucide-static/icons/{icon-name}.svg`. -To use SVGs in your project you can for example use a [SVG loader](https://v4.webpack.js.org/loaders/svg-inline-loader/). +Make sure you have the correct Webpack loader configured, such as [`url-loader`](https://v4.webpack.js.org/loaders/url-loader/). + +### SVG file as string + +To import an SVG as a string (e.g., for templating): ```js import arrowRightIcon from 'lucide-static/icons/arrow-right'; - -// return string of an SVG ``` -### SVG Sprite +You'll need an SVG loader like [`svg-inline-loader`](https://v4.webpack.js.org/loaders/svg-inline-loader/). -You may need additional loader for this. +### Using the SVG sprite + +:::danger +[Not intended for production use.](#production-warning) +::: + +You may also need an additional SVG loader to handle this. + +#### Basic sprite usage (not production-optimized): ```html - +``` - +#### Inline usage: + +```html - - ...sprite svg - + +... ``` -If you'd prefer, you can use CSS to hold your base SVG properties +#### Inline with CSS helper class + +If you'd prefer, you can use CSS to hold your base SVG properties: ```css .lucide-icon { @@ -128,47 +156,71 @@ If you'd prefer, you can use CSS to hold your base SVG properties } ``` -and update the SVG as follows +...and update the SVG as follows: ```xml - - - - ...sprite svg + + + +... ``` -### Icon Font +## Icon font -```css +:::danger +[Not intended for production use.](#production-warning) +::: + +Lucide icons are also available as a web font. To use them, you first need to include the corresponding stylesheet: + +::: code-group + +```css [Vite] +@import 'lucide-static/font/lucide.css'; +``` + +```css [Webpack] @import ('~lucide-static/font/lucide.css'); ``` +```html [CDN] + +``` + +```html [Static asset] + +``` + +::: + +Once included, use the format `icon-{kebab-case-name}`. You can copy icon names from the [Lucide Icons page](https://lucide.dev/icons). + ```html
``` -### Node.js +If you're not using a package manager, you can download the font files directly from the [latest release](https://github.com/lucide-icons/lucide/releases/latest). -To use lucide icons in your Nodejs project you can import each icon as: +## Node.js + +You can also import Lucide icons in Node.js (CommonJS) projects: ```js -const { messageSquare } = require('lucide-static/lib'); +const {messageSquare} = require('lucide-static/lib'); ``` > Note: Each icon name is in camelCase. -#### Example in node.js project +#### Express app example in Node.js ```js const express = require('express'); -const { messageSquare } = require('lucide-static/lib'); +const {messageSquare} = require('lucide-static/lib'); const app = express(); const port = 3000; @@ -181,7 +233,7 @@ app.get('/', (req, res) => {

Lucide Icons

-

This is a lucide icon ${messageSquare}

+

This is a Lucide icon ${messageSquare}