A vite plugin to resolve mono-repo packages from 'src' directory, therefor no need to build packages for easy debugging. :)
# npm
npm install vite-plugin-ts-mono-alias -D
# yarn
yarn add vite-plugin-ts-mono-alias -D
// 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()],
// ...
};
});
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'),
},
}),
],
// ...
};
});
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
],
}),
],
// ...
};
});
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.
- test
MIT