onejs-unity
raw JSON → 0.2.13 verified Fri May 01 auth: no javascript
Unity integration utilities for OneJS (v0.2.13), providing asset loading, esbuild/PostCSS build plugins for USS transformation, and GPU compute APIs. Designed for Unity developers using OneJS to write UI and logic in JavaScript/TypeScript. Key differentiators: automatic path resolution between Editor and Build modes, npm package asset distribution without config, built-in Tailwind-like utility class generation for USS without external tailwindcss dependency, and ES6 import transformation for C# namespaces. Requires react ^18/^19, esbuild >=0.17, postcss >=8, tailwindcss >=3. Ships TypeScript types.
Common errors
error Cannot find module 'onejs-unity/esbuild' ↓
cause Using a bundler or Node version that doesn't resolve package.json exports correctly.
fix
Ensure your bundler (esbuild, webpack, etc.) supports subpath exports. For Node scripts, use Node >=16. Alternatively, import from the main package if the subpath is not required.
error TypeError: loadImage is not a function ↓
cause Misnamed import: likely imported as default instead of named.
fix
Use: import { loadImage } from 'onejs-unity/assets';
error Error: [tailwindPlugin] content option is required ↓
cause Missing content option when initializing tailwindPlugin.
fix
Provide content glob array: tailwindPlugin({ content: ['./src/**/*.{tsx,ts}'] })
Warnings
gotcha The tailwindPlugin does NOT require an external tailwindcss package; it generates USS classes internally. However, the peer dependency 'tailwindcss' is still listed, which may be confusing. ↓
fix You can install tailwindcss as a peer dep to satisfy the requirement, but it is not strictly needed for the USS generation.
gotcha Asset loading functions (loadImage, etc.) are synchronous and may throw if the asset does not exist. Ensure assetExists() checks before loading or wrap in try/catch. ↓
fix Use assetExists() to check availability before loading, or wrap calls in try-catch blocks.
gotcha Import paths for C# namespaces are case-sensitive and must start with an uppercase letter for importTransformPlugin to work. ↓
fix Ensure module names start with an uppercase letter (e.g., 'UnityEngine', not 'unityEngine').
breaking If using an older version of OneJS that does not support subpath imports (e.g., Node <16), require /esbuild or /assets subpaths may fail. ↓
fix Upgrade Node or use a bundler that supports package.json exports.
Install
npm install onejs-unity yarn add onejs-unity pnpm add onejs-unity Imports
- loadImage wrong
import loadImage from 'onejs-unity/assets'correctimport { loadImage } from 'onejs-unity/assets' - importTransformPlugin wrong
const importTransformPlugin = require('onejs-unity/esbuild')correctimport { importTransformPlugin } from 'onejs-unity/esbuild' - ussModulesPlugin wrong
import { ussModulesPlugin } from 'onejs-unity'correctimport { ussModulesPlugin } from 'onejs-unity/esbuild'
Quickstart
import { loadImage } from 'onejs-unity/assets';
import { ussModulesPlugin, tailwindPlugin } from 'onejs-unity/esbuild';
// Load an image asset
const logo = loadImage('images/logo.png');
// esbuild config for USS plugins (e.g., in build script)
const esbuildConfig = {
plugins: [
ussModulesPlugin({ generateTypes: true }),
tailwindPlugin({ content: ['./src/**/*.{tsx,ts}'] }),
],
};