A modern, TypeScript-ready boilerplate for FiveM NUI development using Svelte and Lua. Features built-in visibility management, NUI focus handling, and development tools.
Clone this repository into your resources folder:
cd resources
git clone https://your-repository/fivem-svelte-boilerplate-lua
Install dependencies:
cd fivem-svelte-boilerplate-lua/web/
npm install
Start development server:
npm run dev
or have an auto updating production build via -watch
npm run start:game
Build for production:
npm run build
fivem-svelte-boilerplate-lua/
├── web/ # Web-related files
│ ├── build/ # Production build output
│ ├── node_modules/ # Node.js dependencies
│ ├── public/ # Static assets
│ └── src/ # Source code
│ ├── lib/ # Utility libraries
│ │ ├── nuiFetch.ts # NUI fetch utilities
│ │ ├── nuiListen.ts # NUI event listeners
│ │ └── nuiVisibility.ts # Visibility management
│ ├── app.css # Global styles
│ ├── App.svelte # Main Svelte component
│ └── main.ts # Application entry point
├── client/
│ └── client.lua # Client-side Lua scripts
├── fxmanifest.lua # FiveM resource manifest
├── package.json # Node.js dependencies and scripts
├── svelte.config.js # Svelte configuration
├── tsconfig.json # TypeScript configuration
The boilerplate comes with two built-in example commands:
Toggle UI visibility:
/toggleNui
Update counter value:
/updateCount [number]
// Send data to Lua client
await nuiFetch("eventName", {
// your data here
});
// Listen for messages from Lua client
const cleanup = onNuiMessage<YourDataType>("eventName", (data) => {
// handle the data
});
The boilerplate includes a visibility store that handles UI state:
// In your Svelte component
import { visibility, setVisible } from "./lib/nuiVisibility";
// Read visibility state
$: isVisible = $visibility;
// Update visibility
await setVisible(true); // or false
Add new NUI callbacks in client.lua
:
RegisterNUICallback('eventName', function(data, cb)
-- Handle the event
cb({ status = 'ok' })
end)
Send messages to NUI:
SendNUIMessage({
type = "eventName",
data = {
-- your data here
}
})
The boilerplate includes development utilities:
During development, you can either:
npm run dev
for hot-reload development server via browsernpm run start:game
for auto-updating production build with --watchBuild the UI:
npm run build
Package your resource:
web/build
directoryfxmanifest.lua
MIT License - Feel free to use this boilerplate for your FiveM projects!