Skip to main content

Installation

Learn how to install the Moitribe JavaScript SDK in your project using different methods.

Prerequisites

Before installing the SDK, ensure you have:

  • A Moitribe account and game ID (contact the Veniso team)
  • Node.js 14+ (for npm installation)
  • A modern web browser or Node.js environment

Installation Methods

Install the SDK as a dependency in your project:

npm install @veniso/moitribe-js
Private Package

The SDK is currently a private package. Contact the Veniso team for access credentials.

Git Repository Installation

Install directly from the Git repository:

npm install git+ssh://git@github.com:veniso/moitribe-js-sdk.git

Or add to your package.json:

{
"dependencies": {
"@veniso/moitribe-js": "git+ssh://git@github.com:veniso/moitribe-js-sdk.git"
}
}

Local Path Installation (Development)

For local development or testing:

npm install /path/to/moitribe-js-sdk

CDN Installation

Include the SDK directly in your HTML file:

<!DOCTYPE html>
<html>
<head>
<title>My Game</title>
</head>
<body>
<!-- Your game content -->

<!-- Moitribe SDK -->
<script src="node_modules/@veniso/moitribe-js/dist/moitribe-sdk.min.js"></script>
<script>
// SDK is available as MoitribeSDK
console.log('Moitribe SDK loaded:', typeof MoitribeSDK);
</script>
</body>
</html>

Usage by Environment

Browser (ES6 Modules)

Import the SDK in modern JavaScript:

import MoitribeSDK from '@veniso/moitribe-js';

// Initialize the SDK
MoitribeSDK('your-game-id', 'init', {
loginCallback: (result) => {
if (result.success) {
console.log('Player logged in:', result.playerdata);
}
}
});

Browser (CommonJS)

For older bundlers or require syntax:

const MoitribeSDK = require('@veniso/moitribe-js');

// Initialize the SDK
MoitribeSDK('your-game-id', 'init', {
loginCallback: (result) => {
if (result.success) {
console.log('Player logged in:', result.playerdata);
}
}
});

Browser (Script Tag)

When using the CDN or script tag:

<script src="node_modules/@veniso/moitribe-js/dist/moitribe-sdk.min.js"></script>
<script>
// SDK is available globally as MoitribeSDK
MoitribeSDK('your-game-id', 'init', {
loginCallback: function(result) {
if (result.success) {
console.log('Player logged in:', result.playerdata);
}
}
});
</script>

Node.js

Use the SDK in Node.js applications:

const MoitribeSDK = require('@veniso/moitribe-js');

// Initialize the SDK
MoitribeSDK('your-game-id', 'init', {
loginCallback: (result) => {
if (result.success) {
console.log('Player logged in:', result.playerdata);
}
}
});

TypeScript

Import with full type support:

import MoitribeSDK, { 
GameInitParams,
SignedInProfile
} from '@veniso/moitribe-js';

// Initialize with types
const params: GameInitParams = {
loginCallback: (result: { success: boolean; playerdata?: SignedInProfile }) => {
if (result.success && result.playerdata) {
console.log('Player:', result.playerdata.name);
}
}
};

MoitribeSDK('your-game-id', 'init', params);

Build Tools Configuration

Webpack

The SDK works out of the box with Webpack. No special configuration needed:

// webpack.config.js
module.exports = {
// Your webpack configuration
resolve: {
extensions: ['.js', '.ts', '.json']
}
};

Vite

Add to your Vite project:

// vite.config.js
import { defineConfig } from 'vite';

export default defineConfig({
// Your Vite configuration
optimizeDeps: {
include: ['@veniso/moitribe-js']
}
});

Rollup

Configure Rollup to bundle the SDK:

// rollup.config.js
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';

export default {
input: 'src/main.js',
output: {
file: 'dist/bundle.js',
format: 'iife'
},
plugins: [
resolve(),
commonjs()
]
};

Parcel

Parcel works with zero configuration:

npm install @veniso/moitribe-js
// src/index.js
import MoitribeSDK from '@veniso/moitribe-js';

MoitribeSDK('your-game-id', 'init', {
loginCallback: (result) => console.log(result)
});

TypeScript Configuration

If using TypeScript, ensure your tsconfig.json includes:

{
"compilerOptions": {
"target": "ES2015",
"module": "ESNext",
"moduleResolution": "node",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"skipLibCheck": true
}
}

The SDK includes full TypeScript definitions, so you'll get autocomplete and type checking automatically.

Verifying Installation

After installation, verify the SDK is working:

import MoitribeSDK, { VERSION } from '@veniso/moitribe-js';

console.log('Moitribe SDK Version:', VERSION); // Should print: 1.4.2

Troubleshooting Installation

Module Not Found Error

If you see "Cannot find module '@veniso/moitribe-js'":

  1. Ensure the package is installed: npm list @veniso/moitribe-js
  2. Delete node_modules and reinstall: rm -rf node_modules && npm install
  3. Check that you have access to the private repository

Type Definition Errors

If TypeScript can't find type definitions:

  1. Ensure @types/node is installed: npm install --save-dev @types/node
  2. Check your tsconfig.json includes "esModuleInterop": true
  3. Restart your TypeScript server/IDE

Bundle Size Issues

If your bundle is too large:

  1. Ensure you're using the production build
  2. Enable tree-shaking in your bundler
  3. Use dynamic imports for RTM features if not needed immediately
tip

For the smallest bundle size, import only what you need:

import { GameService, LeaderboardService } from '@veniso/moitribe-js';

Next Steps

Now that you have the SDK installed, learn how to:

Continue to Getting Started to initialize the SDK.