@pma-network/builder
v1.2.8
Published
Build tool for FiveM/RedM resources with watch mode and auto-restart
Readme
@pma-network/builder
A build tool for FiveM/RedM resources with watch mode and auto-restart support.
Features
- 🔄 Auto-restart resources on file changes
- 🎮 Support for both FiveM and RedM
- 📦 Built-in TypeScript/JavaScript bundling with esbuild
- 🌐 Web UI dev server integration
- ⚡ Fast rebuilds with watch mode
- 🎯 Automatic fxmanifest.lua regeneration with customizable fields
Installation
pnpm add -D @pma-network/builder
# or
npm install --save-dev @pma-network/builder
# or
yarn add -D @pma-network/builderUsage
Command Line
Add to your package.json scripts:
{
"scripts": {
"build": "build",
"watch": "build --watch",
"build:redm": "build --redm",
"watch:redm": "build --watch --redm"
}
}Then run:
pnpm build # Build for FiveM
pnpm watch # Watch mode for FiveM
pnpm build:redm # Build for RedM
pnpm watch:redm # Watch mode for RedMProgrammatic API
import { build } from "@pma-network/builder";
await build({
resourceName: "my-resource",
restartEndpoint: "http://127.0.0.1:4689/rr",
restartTimeout: 2000,
debounceDelay: 500,
webDevPort: 5173,
builds: {
client: { platform: "browser", target: "es2021", format: "iife" },
server: { platform: "node", target: "node16", format: "cjs" },
},
});Configuration
Create a build.config.js in your project root:
export default {
restartEndpoint: "http://127.0.0.1:4689/rr",
restartTimeout: 2000,
debounceDelay: 500,
webDevPort: 5173,
builds: {
client: { platform: "browser", target: "es2021", format: "iife" },
server: { platform: "node", target: "node16", format: "cjs" },
},
};fxmanifest.lua
The manifest is regenerated from scratch on every build — it is never patched in place. Customize it via the fxmanifest option:
import { build } from "@pma-network/builder";
await build({
fxmanifest: {
author: "PMA",
description: "My resource",
version: "1.0.0",
lua54: "yes",
dependencies: ["ox_lib", "oxmysql"],
shared_scripts: "@ox_lib/init.lua",
server_scripts: "@oxmysql/lib/MySQL.lua",
files: ["locales/*.json"],
extra: ["provide 'legacy_resource'"],
},
});The builder always emits fx_version, game, rdr3_warning (RedM only), and a <target>_script 'dist/<target>.js' line for each build target. If a web/ directory exists, files { 'html/index.html', 'html/assets/*' } and a ui_page (dev server URL in watch, built HTML in production) are emitted automatically.
For full control, fxmanifest can also be a function that returns raw lines:
await build({
fxmanifest: (ctx) => [
"fx_version 'cerulean'",
`game '${ctx.game}'`,
// ...entirely hand-rolled
],
});GAME Constant
The build tool automatically injects a GAME constant into your code:
// Available globally in your code
if (GAME === "REDM") {
console.log("Running on RedM");
} else {
console.log("Running on FiveM");
}Add this to your types/game.d.ts:
declare global {
const GAME: "REDM" | "FIVEM";
}
export {};License
MIT
