Skip to content

Commit

Permalink
docs: add recipe for custom entrypoints using entrypoints:found
Browse files Browse the repository at this point in the history
  • Loading branch information
abhigyantrips committed Dec 20, 2024
1 parent 6a93651 commit 8412d18
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions docs/guide/essentials/wxt-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,31 @@ This file could then be loaded at runtime:
const res = await fetch(browser.runtime.getURL('/some-text.txt'));
```

#### Add custom entrypoints

Once the existing files under the `entrypoints/` directory have been discovered, the `entrypoints:found` hook can be used to add custom entrypoints.

:::info
The `entrypoints:found` hook is triggered before validation is carried out on the list of entrypoints. Thus, any custom entrypoints will still be checked for duplicate names and logged during debugging.
:::

```ts
import { defineWxtModule } from 'wxt/modules';

export default defineWxtModule({
setup(wxt) {
wxt.hook('entrypoints:found', (_, entrypointInfos) => {
// Add your new entrypoint
entrypointInfos.push({
name: 'my-custom-script',
inputPath: 'path/to/custom-script.js',
type: 'content-script',
});
});
},
});
```

#### Generate runtime module

Create a file in `.wxt`, add an alias to import it, and add auto-imports for exported variables.
Expand Down

0 comments on commit 8412d18

Please sign in to comment.