Files
svg-sprites/skills/artifacts/svg-sprites-ru/references/docs/en/next-pages.md
S.Gromov 81df9027cd feat: добавить локализацию документации и скиллов
- добавлены английские README и руководства с переключением языка
- сборка скиллов разделена на английскую и русскую версии
- локализованные документы включены в npm-пакет
2026-07-11 09:26:43 +03:00

2.0 KiB
Raw Blame History

Next.js Pages Router

← Back to home

Two explicit modes are supported:

Bundler Mode key Next.js version
Turbopack next@pages/turbopack 16.2+
Webpack 5 next@pages/webpack 12.2+

Next.js 12.2 requires React 18.

1. Install the package

npm install @gromlab/svg-sprites

2. Create a sprite module

src/ui/file-manager/svg-sprite/
├── icons/
│   ├── check.svg
│   └── folder.svg
└── svg-sprite.config.ts
// src/ui/file-manager/svg-sprite/svg-sprite.config.ts
import { defineNextSpriteConfig } from '@gromlab/svg-sprites'

export default defineNextSpriteConfig({
  name: 'file-manager',
  description: 'File manager icons',
})

3. Add generation

{
  "scripts": {
    "sprite:file-manager": "svg-sprites --mode next@pages/webpack src/ui/file-manager/svg-sprite",
    "predev": "npm run sprite:file-manager",
    "prebuild": "npm run sprite:file-manager"
  }
}

For Next.js 16.2 with Turbopack, replace the mode key with next@pages/turbopack.

4. Use it on a page

import { FileManagerIcon } from '@/ui/file-manager/svg-sprite'

export default function FilesPage() {
  return <FileManagerIcon icon="folder" width={24} height={24} />
}

export function getServerSideProps() {
  return { props: {} }
}

The component works the same way with SSR, SSG, and client-side navigation. Next.js emits a separate SVG asset with a content hash.

5. Add SpriteViewer

import { SpriteViewer } from '@gromlab/svg-sprites/react'

const sources = [
  () => import('@/ui/file-manager/svg-sprite/manifest'),
]

export default function SpritesPage() {
  return <SpriteViewer sources={sources} />
}

Verify the bundler

# Turbopack
npx next build --turbopack

# Webpack 5
npx next build --webpack

For Next 1215 with Webpack, use npx next build without the flag.

The Next.js command and the generator mode key must target the same bundler.