frontend-development
Provides frontend development guidelines for Nette. Use when working with Vite, SCSS, JavaScript/TypeScript, Nette Assets ({asset} tag, asset mapping), ESLint with @nette/eslint-plugin, Naja AJAX library, frontend entry points, npm packages in Nette context, Tailwind CSS with Latte templates, nette-forms npm package, HMR, build commands (npm run dev/build), or passing data from PHP to JavaScript.
What this skill does
## Frontend Development
Frontend built with modern tooling and seamlessly integrated with Nette backend through Nette Assets.
See [the Nette Assets reference](references/assets.md) for asset management.
See [the Vite integration guide](references/vite.md) for build configuration.
### Technology Stack
- **Build system:** Vite with TypeScript support
- **JavaScript:** ES Modules (ESM) with `"type": "module"` in package.json
- **Styling:** SCSS with modular component architecture
- **Asset integration:** Nette Assets for PHP-frontend bridge
- **Admin framework:** Bootstrap for rapid interface development
- **Code quality:** ESLint with @nette/eslint-plugin
- **Forms:** Nette Forms with progressive enhancement
## Asset Architecture Strategy
**Source vs Built Assets separation:**
- **Development assets:** `assets/` directory with source files (SCSS, TypeScript, images)
- **Production assets:** `www/assets/` with optimized, versioned files for browsers
### Coding Standards
- Use single quotes for strings unless containing apostrophes (CSS, SCSS, JavaScript)
### Entry Point Decision Matrix
**Use separate entry points when:**
- Different user contexts with distinct dependencies (frontend vs admin)
- Bundle size optimization is critical
**Example strategy:**
```javascript
// assets/front.js - Public website (custom design)
import './css/front.scss';
import './js/components/product-gallery.js';
// assets/admin.js - Administration (Bootstrap-based)
import 'bootstrap/dist/css/bootstrap.css';
import './css/admin.scss';
```
### Organization Patterns
**File-per-component approach:**
```
assets/js/
├── components/
│ ├── product-form.js ← Reusable form component
│ ├── image-gallery.js ← Product image viewer
├── pages/
│ ├── blog.css ← Page-specific enhancements
│ └── checkout.css ← Multi-step checkout flow
└── utils/
├── ajax.js ← AJAX utilities
└── validation.js ← Form validation helpers
```
### Nette Assets Integration Patterns
**Basic asset loading**
```latte
{* Loads complete bundle with all dependencies *}
{asset 'front.js'}
```
**Configuration**
```neon
assets:
mapping:
default:
type: vite
devServer: true # Enable HMR in debug mode
```
### Data Flow from Backend to Frontend
**Passing data to JavaScript:**
```latte
{* In template *}
<script>
window.appConfig = {
apiUrl: {$baseUrl . '/api'},
userId: {$user->isLoggedIn() ? $user->getId() : null},
locale: {$locale},
csrfToken: {$csrfToken}
};
</script>
{asset 'front.js'}
```
Latte automatically applies context-sensitive escaping – values inside `<script>` are JSON-encoded, so strings get quoted and `null` stays `null`.
```javascript
// In JavaScript component
const { apiUrl, userId, csrfToken } = window.appConfig;
fetch(`${apiUrl}/user-data`, {
headers: { 'X-CSRF-Token': csrfToken }
});
```
### Naja (AJAX Library)
Naja is the standard AJAX library for Nette – it handles snippet redrawing, form submissions, and history integration:
```shell
npm install naja
```
```javascript
import naja from 'naja';
// Initialize after DOM is ready
naja.initialize();
```
Naja automatically intercepts links and forms with the `ajax` CSS class and handles snippet updates from the server. See [Naja documentation](https://naja.js.org/) for configuration and extensions.
### Nette Forms Integration
Requires `nette-forms` npm package:
```shell
npm install nette-forms
```
**Standard enhancement pattern:**
```javascript
import netteForms from 'nette-forms';
// Initialize Nette Forms validation
netteForms.initOnLoad();
```
### ESLint Configuration
```shell
npm install --save-dev @nette/eslint-plugin eslint
```
**Basic configuration with recommended rules:**
```javascript
// eslint.config.js
import nette from '@nette/eslint-plugin';
import { defineConfig } from 'eslint/config';
export default defineConfig([
{
extends: [nette.configs.recommended],
},
]);
```
**Linting JavaScript in Latte templates:**
```shell
npm install --save-dev eslint-plugin-html
```
```javascript
// eslint.config.js
import nette from '@nette/eslint-plugin';
import pluginHtml from 'eslint-plugin-html';
import { defineConfig } from 'eslint/config';
export default defineConfig([
{
extends: [nette.configs.recommended],
},
{
files: ['app/**/*.latte'],
plugins: {
html: pluginHtml,
},
processor: '@nette/latte', // Handles Latte tags in JS
},
]);
```
This allows ESLint to check JavaScript inside `<script>` tags with Latte variables:
```latte
<script>
let name = {$name};
</script>
```
**TypeScript support:**
```shell
npm install --save-dev typescript typescript-eslint
```
```javascript
import nette from '@nette/eslint-plugin/typescript';
export default defineConfig([
{
extends: [nette.configs.typescript],
},
]);
```
**Custom rules:**
- `@nette/no-this-in-arrow-except` - Prevents `this` binding issues in arrow functions
- `@nette/prefer-line-comments` - Enforces `//` over `/* */` for single-line comments
### Tailwind CSS Integration
When using Tailwind CSS, configure it to scan Latte templates for class names:
```css
/* assets/css/app.css */
@import 'tailwindcss';
@source '../app/**/*.latte';
```
### Essential Commands
```bash
# Start the development server with HMR
npm run dev
# Build assets for production
npm run build
# Build assets for development
npm run build:dev
# Run ESLint checks
npm run lint
# Run ESLint and fix issues
npm run lint:fix
```
### Online Documentation
For detailed information, use WebFetch on these URLs:
- [Assets](https://doc.nette.org/en/assets) – Nette Assets documentation
- [Naja](https://naja.js.org/) – AJAX library for Nette
Related in Web Dev
generating-lwc-components
IncludedLightning Web Components with PICKLES methodology and 165-point scoring. Use this skill when the user creates or edits LWC components, builds wire service patterns, or writes Jest tests for LWC. TRIGGER when: user creates/edits LWC components, touches lwc/**/*.js, .html, .css, .js-meta.xml files, or asks about wire service, SLDS, or Jest LWC tests. DO NOT TRIGGER when: Apex classes (use generating-apex), Aura components, or Visualforce.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Set up queries with useQuery, mutations with useMutation, configure QueryClient caching strategies, implement optimistic updates, and handle infinite scroll with useInfiniteQuery. Use when: setting up data fetching in React projects, migrating from v4 to v5, or fixing object syntax required errors, query callbacks removed issues, cacheTime renamed to gcTime, isPending vs isLoading confusion, keepPreviousData removed problems.
document-processor-api
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
nutrient-document-processing
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Covers useMutationState, simplified optimistic updates, throwOnError, network mode (offline/PWA), and infiniteQueryOptions. Use when setting up data fetching, fixing v4→v5 migration errors (object syntax, gcTime, isPending, keepPreviousData), or debugging SSR/hydration issues with streaming server components.
accelint-nextjs-best-practices
IncludedNext.js performance optimization and best practices. Use when writing Next.js code (App Router or Pages Router); implementing Server Components, Server Actions, or API routes; optimizing RSC serialization, data fetching, or server-side rendering; reviewing Next.js code for performance issues; fixing authentication in Server Actions; or implementing Suspense boundaries, parallel data fetching, or request deduplication.