Skip to content

Getting started

Requirements

Suggested knowledge

You don’t need to be an expert (or have worked) in the above subjects, but it makes creating extensions much easier. We believe in learning by doing, so don’t be afraid to ask for help in our Discord server or reference other extensions.

Reading how other extensions work can be a huge resource, so we encourage you to reference the moonlight core extensions and the extensions on the official repository if you’re stuck. Just remember to respect the licensing of the extension!

Create your extension

The create-extension CLI tool can help you scaffold a new moonlight extension repository:

  • Configured like a monorepo, so multiple extensions can live in the same Git repository
  • Pre-configured build system (esbuild)
  • Pre-configured formatter and linter (Prettier and ESLint)
  • TypeScript support
  • Example usage of patching, Webpack modules, and Node.js code

You’ll need to decide on a few things first:

  • Pick a name for your extension. This will be displayed to the user in Moonbase. We suggest a short but informational one.
  • Pick an ID for your extension. We suggest using the name of your extension in camelCase:
    • Context Menu -> contextMenu
    • Moonbase -> moonbase
    • No Hide Token -> noHideToken

Now, run this command and follow the instructions:

Terminal window
$ pnpm create @moonlight-mod/extension

After the project is created, change the meta field in manifest.json:

  • Change name to your user-facing extension name.
  • Change tagline to a short explanation of your extension.
  • Change or delete description to a longer explanation of your extension. If you have any important notes about the extension’s functionality, add them here.
  • Change authors to contain your username.
  • Change source to the URL of your Git repository.

Now is a good time to take a look around the rest of the files - most of them are commented. We strongly suggest adding a short README to your project, as well as a LICENSE.

Build and run the extension

Run pnpm run build to build the extension. If you get an error, you might have forgotten to install the dependencies (pnpm i). Use the “Extension search paths” setting in Moonbase (or set devSearchPaths in your moonlight config) to add the dist folder next to your code. If you don’t have a dist folder, you need to build the extension first.

After restarting your client, the extension will be available in Moonbase and you can enable it. We suggest using watch mode (pnpm run dev) when developing your extension to build it automatically.

Publish to GitHub

We suggest publishing to GitHub to make use of the provided GitHub workflow. You can choose any Git host you like, though!

In the repository settings, make sure GitHub Actions is enabled for your repository, and that the GitHub Pages source is set to GitHub Actions:

  • GitHub Actions: “Code and automation” > “Actions” > “General” > “Actions permissions”
  • GitHub Pages: “Code and automation” > “Pages” > “Build and deployment” > “Source”

Your repository will be published to https://<username>.github.io/<repository>/repo.json. Every time a commit is made to the main branch, the extensions will be built on GitHub Actions and published automatically.

It is suggested to only use this if you do not plan to submit to the official repository. You can also delete the .github/workflows/deploy.yml file if you do not want this (or if you aren’t using GitHub).

What’s next?

Congrats on making it this far! There’s a lot more to learn about how moonlight works:

If you need any help, don’t be afraid to ask in our Discord server.