Imports and npm dependencies
Server dependencies
Section titled “Server dependencies”Server scripts run in Node.js. Install npm dependencies in your mod’s directory,
alongside its package.json. Node resolves them from node_modules and provides
built-in modules such as node:fs and node:crypto.
For .js files using import and export, set "type": "module" in the mod’s
package.json. .mjs files use ES modules and .cjs files use CommonJS.
See Node.js module formats.
The runtime supplies revo-server and revo-shared through both import and
require(). The @revomp/types-* packages provide their editor declarations.
For TypeScript configuration, see TypeScript setup.
Deploy your package.json and lockfile with the server scripts, then install
runtime dependencies with npm ci --omit=dev. Keep packages imported by the
running server in dependencies. Build tools and typings belong in
devDependencies. See Project directory layout
for how these folders fit together.
Client imports
Section titled “Client imports”Client scripts run as ES modules, starting at scripts/client.js in the client
resource package. Import other files from that entry using relative paths:
import * as revo from 'revo-client';import * as natives from 'natives';import './interactions/index.js';The client provides three built-in modules:
| Import | Contents |
|---|---|
revo-client |
Client API, including shared types and utilities. |
revo-shared |
Shared types and utilities, such as Vector3 and hash. |
natives |
GTA native functions. |
Relative imports resolve from the importing file. Keep their targets inside
scripts/ and include the file name and .js extension. Both static imports
and import('./file.js') are supported.
Use relative paths for script imports. resources:// URLs are accepted by
resource APIs such as WebViews and audio.
Bundle client dependencies
Section titled “Bundle client dependencies”The game client’s loader resolves the built-in modules and relative files. To use an npm package, include its JavaScript in your client build.
Choose packages compatible with the game runtime. Dependencies on Node.js APIs
such as process, Buffer or node:fs, and browser APIs such as window or
document, need their respective environments. Keep database and filesystem
work on the server and browser UI code in a WebView.
For example, install esbuild in your mod’s directory:
npm install --save-dev esbuildKeep your client source at src/client/client.js. Save this build script as
build-client.mjs in the mod’s directory:
// @ts-checkimport { build } from 'esbuild';
await build({ entryPoints: ['src/client/client.js'], outfile: 'client/scripts/client.js', bundle: true, format: 'esm', platform: 'neutral', mainFields: ['module', 'main'], external: ['revo-client', 'revo-shared', 'natives'],});Run it from the same directory:
node build-client.mjsThis writes client/scripts/client.js. Point resources.pack.path at the
client folder, as in the project layout guide.
format: 'esm' keeps the output compatible with the client loader. The neutral
platform and mainFields configure package resolution. The three external
imports remain in the output for the client to provide at runtime.
See esbuild’s platform and
external options.
Install libraries used by your client source with npm, then rebuild after changing the source or dependencies. Run this build before packaging client resources. The packer’s JavaScript processing handles each output file separately, after bundling.
Shared code and WebViews
Section titled “Shared code and WebViews”Shared constants, validation and other JavaScript can be imported by both your server code and client build. Keep environment-specific API imports in the corresponding entry points. Client builds include any shared code they use.
Build a WebView frontend with its own browser target and place the output in the client resources. Its JavaScript runs in Chromium and communicates with the game client through the WebView bridge.