-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
86 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
--- | ||
title: Cookbook | ||
description: Common patterns when writing extensions | ||
sidebar: | ||
order: 10 | ||
--- | ||
|
||
## Exporting styles | ||
|
||
```ts title="index.ts" | ||
export const styles: string[] = [ | ||
`.alert { | ||
color: red; | ||
}` | ||
]; | ||
``` | ||
|
||
## Using mappings | ||
|
||
In this case, the Flux dispatcher. Import types may be wrong in some scenarios (try `import * as Something` or `import { Something }` if you get errors, and let us know!). | ||
|
||
```ts title="index.ts" | ||
export const webpackModules: Record<string, ExtensionWebpackModule> = { | ||
something: { | ||
dependencies: [ | ||
{ | ||
id: "discord/Dispatcher" | ||
} | ||
] | ||
} | ||
}; | ||
``` | ||
|
||
```ts title="webpackModules/something.ts" | ||
import Dispatcher from "@moonlight-mod/wp/discord/Dispatcher"; | ||
|
||
Dispatcher.subscribe("MESSAGE_CREATE", (data) => { | ||
console.log(data); | ||
}); | ||
``` | ||
|
||
## Custom React component | ||
|
||
```ts name="index.ts" | ||
export const webpackModules: Record<string, ExtensionWebpackModule> = { | ||
element: { | ||
dependencies: [ | ||
{ | ||
id: "react" | ||
} | ||
] | ||
} | ||
}; | ||
``` | ||
|
||
```ts name="webpackModules/element.ts" | ||
import React from "@moonlight-mod/wp/react"; | ||
|
||
export default function MyElement() { | ||
return <span>Hello, world!</span>; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters