Files
lucide/docs/guide/packages/lucide-static.md

273 lines
5.7 KiB
Markdown
Raw Permalink Normal View History

2021-11-21 21:08:10 +01:00
# Lucide Static
Static assets and utilities for Lucide icons that work without JavaScript frameworks. This package provides multiple formats including individual SVG files, SVG sprites, icon fonts, and Node.js utilities for server-side rendering and static site generation.
**What you can accomplish:**
- Use individual SVG files as images or CSS background images
- Implement icon fonts for CSS-based icon systems
- Create SVG sprites for efficient icon loading in static sites
- Import SVG strings in Node.js applications and server-side rendering
- Build static websites and applications without JavaScript framework dependencies
This package includes the following implementations of Lucide icons:
2021-11-21 21:08:10 +01:00
- Individual SVG files
- SVG sprite
- Icon font files
- A JavaScript library exporting SVG strings
2021-11-21 21:08:10 +01:00
## Who is this for?
2021-11-21 21:08:10 +01:00
`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:
2021-11-21 21:08:10 +01:00
- 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)
:::
2021-11-21 21:08:10 +01:00
## Installation
::: code-group
```sh [pnpm]
pnpm add lucide-static
```
2021-11-21 21:08:10 +01:00
```sh [yarn]
yarn add lucide-static
```
2021-11-21 21:08:10 +01:00
```sh [npm]
2021-11-21 21:08:10 +01:00
npm install lucide-static
```
```sh [bun]
bun add lucide-static
```
:::
## SVG Files
2021-11-21 21:08:10 +01:00
You can use standalone SVG files or SVG sprites in several ways.
2021-11-21 21:08:10 +01:00
Check out our [codesandbox example](https://codesandbox.io/s/using-the-svg-sprite-lz1kk).
2021-11-21 21:08:10 +01:00
### SVG file as image
2021-11-21 21:08:10 +01:00
#### In HTML:
2021-11-21 21:08:10 +01:00
::: code-group
2021-11-21 21:08:10 +01:00
```html [Webpack]
<!-- SVG file for a single icon -->
2024-12-04 09:48:15 +01:00
<img src="~lucide-static/icons/house.svg" />
2021-11-21 21:08:10 +01:00
```
```html [CDN]
<!-- SVG file for a single icon -->
<img src="https://unpkg.com/lucide-static@latest/icons/house.svg" />
```
:::
#### In CSS:
::: code-group
```css [Webpack]
2024-12-04 09:48:15 +01:00
.house-icon {
background-image: url(~lucide-static/icons/house.svg);
2021-11-21 21:08:10 +01:00
}
```
```css [CDN]
.house-icon {
background-image: url(https://unpkg.com/lucide-static@latest/icons/house.svg);
}
```
:::
Make sure you have the correct Webpack loader configured, such as [`url-loader`](https://v4.webpack.js.org/loaders/url-loader/).
2021-11-21 21:08:10 +01:00
### SVG file as string
2021-11-21 21:08:10 +01:00
To import an SVG as a string (e.g., for templating):
2021-11-21 21:08:10 +01:00
::: code-group
```js [Webpack]
import arrowRightIcon from 'lucide-static/icons/arrow-right';
2021-11-21 21:08:10 +01:00
```
```js [Vite]
import arrowRightIcon from 'lucide-static/icons/arrow-right.svg?raw';
```
:::
You'll need an SVG loader like [`svg-inline-loader`](https://v4.webpack.js.org/loaders/svg-inline-loader/).
### Using the SVG sprite
:::danger
[Not intended for production use.](#production-warning)
:::
2021-11-21 21:08:10 +01:00
You may also need an additional SVG loader to handle this.
#### Basic sprite usage (not production-optimized):
2021-11-21 21:08:10 +01:00
```html
2024-12-04 09:48:15 +01:00
<img src="lucide-static/sprite.svg#house" />
```
#### Inline usage:
2021-11-21 21:08:10 +01:00
```html
2021-11-21 21:08:10 +01:00
<svg
width="24"
height="24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<use href="#alert-triangle" />
</svg>
<!-- sprite SVG -->
<svg>...</svg>
2021-11-21 21:08:10 +01:00
```
#### Inline with CSS helper class
If you'd prefer, you can use CSS to hold your base SVG properties:
2021-11-21 21:08:10 +01:00
```css
.lucide-icon {
width: 24px;
height: 24px;
stroke: currentColor;
fill: none;
stroke-width: 2;
stroke-linecap: round;
stroke-linejoin: round;
2021-11-21 21:08:10 +01:00
}
```
...and update the SVG as follows:
2021-11-21 21:08:10 +01:00
New site! 🚀 (#1275) * add new docs * Add styling * Move files * Add active selection * improve grid overview * improve grid * Add icon detail page * Minor changes * Fix icon preview * optimize home card * Add code examples * Add gitignore * correct temp directory * Add first cusotmizer * Add customizer * fix images paths * Add reset function * Adjust category rendering * Add packages section * Some fixes * Fix vercel build icon * Small code adjustment * move file * Try this * Add code groups with syntax highlighting * Add search icon * Cleanup * update lockfile * turnoff 404 * remove docs/iconMetaData.ts * fix build * Fix build 2 * cleanup * Add icon customizer * Fix build * Add steps * Add Button menu * A lot off fixes! * cleanup * Fix build * Css fixes * Override menu icon * try this to improve preformance * minor improvements * add comment * add readme * Add title * minor fixes * Fixes sliders + removes random backticks from index * Added package list base, still WIP * Added Guide+Source buttons to package list items * Responsive support for XS screens * Map categories count * Adjust tooltip hover position * Add see in action icon * Add download options * Aligns category list items to baseline and decreases category count weight * Fixes event target error for categorylistitems * Added icon release metadata builder * Adds version badges to hero + icon detail overlay * Added contributors. Added Copy Angular. Added release info to icon page. * Centres contributor tooltip * Fixed stroke step + added reset button * Extracted reset button as a separate component for reusability * Makes HomeIconCustomizerIcons less dense * Fixes Button menu * adjust versions and contributors styling on detail page * Fix build? * Fix build 2? * Fix build 3 * Fix build 4 * Fix build 5? * Add latest gh-icon changes * Add comment * Try fetch tags to retrieve release data * try fetch all tags * Add related icons * Add stikcy search bar * Add no results components * Try to fix animation * Try optimizing for categories * Hide buggy animated icon * minor fixes * Add footer * Add contributute link in footer * Add copy name * Add 100% preview icons * remove site directory * clean up * Add redirects * Fix build? * fix redirect? * minor improvements * Fix icons preview on mobile * Small preformance improvement * Dark mode fixes for package icons * Sort related icons by similarity + somewhat better name similarity matching * Replace icon design guide images with uniform SVGs * update lockfile * Adds git clone to manually fetch the main repository for creating release metadata * Remove initial v0.0.0 from release metadata * Add extra CTA to no results behaviour * Remove tags, as they are too overused * Revert "Remove tags, as they are too overused" This reverts commit 909b7563c0c5d98d7eb6e1fa2708d20fc9ecfbf7. * Checkout icons from main * Add absoluteStrokeWidth switch * Add absolute strokewidth to home customizer * Add absolute strokewidth to copy code button * remove unused import * compare build time * improve build speed * Try new release meta data script * add fetch tags * try with branch and remote * try with url * try without ssh * Fix fetch tags in build file * Cleanup * Fix fallback * improve release data * delete relatedIcons.json, because it should be gitignored * Add icon details * Fix import * minor fixes * Try running script parallel * Revert icon details * include aliases in release meta data * Final fixes * Final fixes 2 * minor code adjustment * Fix build * test * Revert concurrent build flow * switch back to concurrent build strategy * revert icon changes * update package.json * update package.json * dedube packages --------- Co-authored-by: Karsa <karsa@karsa.org>
2023-06-04 16:59:38 +02:00
```xml
2021-11-21 21:08:10 +01:00
<svg
xmlns="http://www.w3.org/2000/svg"
class="lucide-icon"
>
<use href="#triangle-alert" />
2021-11-21 21:08:10 +01:00
</svg>
<!-- sprite SVG -->
<svg>...</svg>
2021-11-21 21:08:10 +01:00
```
## Icon font
2021-11-21 21:08:10 +01:00
:::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');
2021-11-21 21:08:10 +01:00
```
```html [CDN]
<link rel="stylesheet" href="https://unpkg.com/lucide-static@latest/font/lucide.css" />
```
```html [Static asset]
<link rel="stylesheet" href="/your/path/to/lucide.css" />
```
:::
Once included, use the format `icon-{kebab-case-name}`. You can copy icon names from the [Lucide Icons page](https://lucide.dev/icons).
2021-11-21 21:08:10 +01:00
```html
2024-12-04 09:48:15 +01:00
<div class="icon-house"></div>
2021-11-21 21:08:10 +01:00
```
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).
## Node.js
2021-11-21 21:08:10 +01:00
You can also import Lucide icons in Node.js projects:
2021-11-21 21:08:10 +01:00
::: code-group
```js [ESM]
import {MessageSquare} from 'lucide-static';
2021-11-21 21:08:10 +01:00
```
```js [CommonJs]
const {MessageSquare} = require('lucide-static');
```
:::
> Note: Each icon name is in PascalCase.
2021-11-21 21:08:10 +01:00
#### Express app example in Node.js
2021-11-21 21:08:10 +01:00
```js
import express from 'express';
import {MessageSquare} from 'lucide-static';
const app = express();
const port = 3000;
2021-11-21 21:08:10 +01:00
app.get('/', (req, res) => {
res.send(`
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>Lucide Icons</h1>
<p>This is a Lucide icon ${MessageSquare}</p>
2021-11-21 21:08:10 +01:00
</body>
</html>
`);
});
2021-11-21 21:08:10 +01:00
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});
2021-11-21 21:08:10 +01:00
```