Cookbook
Exporting from your extension
On the web target (index.ts
), you can export patches, Webpack modules, and styles:
All exports are optional.
Extension entrypoints
Extensions can load in three different environments:
- In the browser (the “web” environment where Discord lives):
index.ts
& Webpack modules - On the Node.js side, where DiscordNative and such live:
node.ts
- On the host, with little sandboxing and access to Electron APIs:
host.ts
Most extensions only need to run code in the browser. Use the Node environment if you need access to system APIs, like the filesystem or creating processes. Use the Host environment if you need to use the Electron API.
Remember that you cannot directly import Node.js modules, and should share code with moonlight.getNatives
.
Sharing code between Node.js and the web
Make a node.ts
file:
Then, use it from your extension:
Remember to restart the dev server.
Using another extension as a library
Mark the extension as a dependency of your extension:
Mark the Webpack module as a dependency of your own Webpack module:
Then, import the Webpack module:
Remember to restart the dev server.
Making a custom React component
Mark React as a dependency of your own Webpack module:
Then, import React from mappings:
React must be imported when using JSX.
Using Spacepack to find code dynamically
Remember to add your find to your extension dependencies and declare Spacepack as a dependency.