Skip to content

A vite plugin for resolving mono-repo packages from 'src' directory

License

Notifications You must be signed in to change notification settings

gary-Shen/vite-plugin-ts-mono-alias

Repository files navigation

vite-plugin-ts-mono-alias

A vite plugin to resolve mono-repo packages from 'src' directory, therefor no need to build packages for easy debugging. :)

screenshot

Usage

# npm
npm install vite-plugin-ts-mono-alias -D
# yarn
yarn add vite-plugin-ts-mono-alias -D

Configuration

// vite.config.ts
import tsMonoAlias from 'vite-plugin-ts-mono-alias';
import { defineConfig } from 'vite';

// https://vitejs.dev/config/
export default defineConfig(() => {
  return {
    // ...
    plugins: [tsMonoAlias()],
    // ...
  };
});

Options

alias

Define alias for packages.

example:

// vite.config.ts
import tsMonoAlias from 'vite-plugin-ts-mono-alias';
import { defineConfig } from 'vite';
import { join } from 'path';

// https://vitejs.dev/config/
export default defineConfig(() => {
  return {
    // ...
    plugins: [
      tsMonoAlias({
        alias: {
          '@example/package-a': '../../../package-a/lib',
          '@example/package-b': ({ dir }) => join(dir, 'index.ts'),
        },
      }),
    ],
    // ...
  };
});

ignorePackages

default: [process.cwd()]

Ignore packages from redirecting.

example:

// vite.config.ts
import tsMonoAlias from 'vite-plugin-ts-mono-alias';
import { defineConfig } from 'vite';

// https://vitejs.dev/config/
export default defineConfig(() => {
  return {
    // ...
    plugins: [
      tsMonoAlias({
        ignorePackages: [
          'package-a', // by package name
          '../package-b', // by path
        ],
      }),
    ],
    // ...
  };
});

exact

default false.

Exactly match the importee. Such as

import a from '@example/package-a'; - Will work.

import a from '@example/package-a/lib/foo'; - Will not work.

TODO

  • test

License

MIT