Skip to content

jwyGithub/rsbuild-plugin-auto-alias

Repository files navigation

rsbuild-plugin-auto-alias

automatically generate alias based on path

version download issues license


Features

  • Support for custom alias prefixes
  • Supports synchronous mode configuration

Install

pnpm

pnpm add rsbuild-plugin-auto-alias -D

yarn

yarn add rsbuild-plugin-auto-alias -D

npm

npm install rsbuild-plugin-auto-alias -D

Use

rsbuild.config.ts / rsbuild.config.js

import { defineConfig } from '@rsbuild/core';
import { pluginAutoAlias } from 'rsbuild-plugin-auto-alias';

export default defineConfig({
    plugins: [pluginAutoAlias({})]
});

Option

export interface AutoAlias {
    /**
     * @description the root directory where the alias needs to be generated is src by default
     * @default src
     */
    root?: string;

    /**
     * @description prefix for generating aliases
     * @default @
     */
    prefix?: string;

    /**
     * @description synchronize the mode of json configuration
     * @default all
     */
    mode?: 'sync' | 'off';

    /**
     * @description alias configuration file path
     * @default tsconfig.json
     */
    aliasPath?: string;
}

tsconfig.json / jsconfig.json

{
    "compilerOptions": {
        "baseUrl": "./"
        // ...
    }
}

Example

|-- src
    |-- plugins
    |-- router
    |-- scss
    |-- store
    |-- utils
    |-- views
    |-- ....
import xxx from '@plugins/xxx';
import xxx from '@router/xxx';
import xxx from '@scss/xxx';
import xxx from '@store/xxx';
import xxx from '@utils/xxx';
import xxx from '@views/xxx';

About

automatically generate alias based on path

Resources

License

Stars

Watchers

Forks

Packages

No packages published