> ## Documentation Index
> Fetch the complete documentation index at: https://illegalcord.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Webpack and Patches

> Find Discord Webpack modules and write source patches using the local Illegalcord APIs.

Discord code is bundled through Webpack. Illegalcord exposes lazy finders and a patch system so plugins can use Discord internals without importing them directly.

## Lazy finders

Use lazy finders at module scope:

```typescript theme={null}
import { findByPropsLazy, findComponentByCodeLazy, findStoreLazy } from "@webpack";

const VoiceActions = findByPropsLazy("toggleSelfMute");
const GuildStore = findStoreLazy("GuildStore");
const SomeComponent = findComponentByCodeLazy(".someStableCodeFragment");
```

Common stores and utilities are often already exported from `@webpack/common`:

```typescript theme={null}
import { FluxDispatcher, React, UserStore, useStateFromStores } from "@webpack/common";
```

<Tip>
  Before adding a finder, check `src/webpack/common`. Many stores and utilities are already mapped there.
</Tip>

## CSS classes

Use `findCssClassesLazy` for Discord's mangled class names:

```typescript theme={null}
import { findCssClassesLazy } from "@webpack";

const classes = findCssClassesLazy("container", "avatar");
```

Do not hardcode generated class prefixes or suffixes in plugin CSS.

## Declarative patches

Webpack source patches live on the plugin object:

```typescript theme={null}
import { EquicordDevs } from "@utils/constants";
import definePlugin from "@utils/types";

export default definePlugin({
    name: "PatchExample",
    description: "Shows the shape of a Webpack patch.",
    authors: [EquicordDevs.irritably],

    patches: [
        {
            find: "stableSourceString",
            replacement: {
                match: /stableSourceString.{0,80}?targetCall\(/,
                replace: "$&$self.beforeTarget(arguments[0]),"
            }
        }
    ],

    beforeTarget(value: unknown) {
        return value;
    }
});
```

Use `$self` only for methods that live on the plugin object.

## Patch rules

* Prefer string `find` anchors.
* Use stable strings such as intl keys, action types, paths, or distinctive code.
* Keep regex gaps bounded, usually `.{0,150}?`.
* Capture only what you reuse.
* Use `group: true` when multiple replacements must succeed together.
* Use `predicate`, `fromBuild`, or `toBuild` for version or target gates.
* Keep replacement strings small and move logic into plugin methods.

<Warning>
  Do not write broad patches with unbounded `.*?` or `.+?`. They are fragile and can rewrite the wrong module after Discord updates.
</Warning>
