Skip to content

API / wxt/modules / addAlias

Function: addAlias()

addAlias(wxt, alias, path): void

Source: packages/wxt/src/modules.ts:215

Adds an import alias to the project's TSConfig paths and bundler. Path can be absolute or relative to the project's root directory.

Usually, this is used to provide access to some code generated by your module. In the example below, a i18n plugin generates a variable that it wants to provide access to, so it creates the file and adds an import alias to it.

Parameters

wxt

Wxt

alias

string

path

string

Returns

void

Example

ts
import path from 'node:path';

  export default defineWxtModule((wxt) => {
    const i18nPath = path.resolve(wxt.config.wxtDir, 'i18n.ts');

    // Generate the file
    wxt.hooks.hook('prepare:types', (_, entries) => {
      entries.push({
        path: i18nPath,
        text: `export const i18n = ...`,
      });
    });

    // Add alias
    addAlias(wxt, '#i18n', i18nPath);
  });

Generated using typedoc-plugin-markdown and TypeDoc