{"library":"rollup-plugin-typescript-paths","title":"Rollup TypeScript Path Aliases Plugin","description":"rollup-plugin-typescript-paths is a Rollup plugin designed to automatically resolve TypeScript path aliases (defined in tsconfig.json's `paths` and `baseUrl` options) *after* your TypeScript code has already been transpiled. It is currently stable at version `1.5.0` and receives regular updates, with several minor releases in the past year addressing features and bug fixes. This plugin fills a specific niche for projects that use separate TypeScript transpilation steps (e.g., Babel, swc, tsc --emitDeclarationOnly) before bundling with Rollup, rather than relying on Rollup plugins that handle TypeScript compilation directly (like `rollup-plugin-typescript`). Its key differentiators include requiring no configuration for basic usage, robust wildcard support, and leveraging the official TypeScript API's `nodeModuleNameResolver` for accurate path resolution. It ensures that Rollup understands imports like `@utils/foo` when `tsconfig.json` maps `@utils/*` to `src/helpers/utils/*`.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install rollup-plugin-typescript-paths"],"cli":null},"imports":["import { typescriptPaths } from 'rollup-plugin-typescript-paths';","import { typescriptPaths } from 'rollup-plugin-typescript-paths';","import type { Options } from 'rollup-plugin-typescript-paths';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"/* rollup.config.js */\nimport { typescriptPaths } from 'rollup-plugin-typescript-paths';\nimport typescript from '@rollup/plugin-typescript'; // Used here for declaration generation\n\n// --- Context: Minimal tsconfig.json for this example ---\n// Create a `tsconfig.json` in your project root with:\n// {\n//   \"compilerOptions\": {\n//     \"target\": \"es2018\",\n//     \"module\": \"esnext\",\n//     \"baseUrl\": \".\",\n//     \"paths\": {\n//       \"@components/*\": [\"src/components/*\"],\n//       \"@utils\": [\"src/lib/utils/index.ts\"]\n//     },\n//     \"lib\": [\"es2018\", \"dom\"],\n//     \"declaration\": true,\n//     \"emitDeclarationOnly\": true,\n//     \"strict\": true\n//   },\n//   \"include\": [\"src/**/*.ts\"],\n//   \"exclude\": [\"node_modules\"]\n// }\n\n// --- Context: Source files for this example ---\n// Create `src/index.ts`:\n// import { greeting } from '@utils';\n// import { Button } from '@components/Button';\n// console.log(greeting('Rollup'));\n// new Button().render();\n\n// Create `src/lib/utils/index.ts`:\n// export const greeting = (name: string) => `Hello, ${name}!`;\n\n// Create `src/components/Button.ts`:\n// export class Button { render() { console.log('Button rendered!'); } }\n\nexport default {\n  input: 'src/index.ts',\n  output: {\n    dir: 'dist',\n    format: 'es',\n    sourcemap: true,\n  },\n  plugins: [\n    // Use @rollup/plugin-typescript for declaration files only, or skip if already transpiled\n    typescript({ declaration: true, declarationDir: 'dist/types', emitDeclarationOnly: true }),\n    typescriptPaths({\n      // Optional: Set to true if you want to resolve non-relative paths\n      // based on tsconfig's baseUrl even if no `paths` are matched.\n      nonRelative: true,\n      // Optional: Custom path to your tsconfig.json if not in project root\n      // tsConfigPath: './configs/tsconfig.build.json',\n      transform: (path, id) => {\n        // Example: Log the resolved paths for debugging\n        // console.log(`Resolved import ${id} to ${path}`);\n        return path;\n      }\n    }),\n  ],\n};","lang":"typescript","description":"This quickstart demonstrates how to configure Rollup with `rollup-plugin-typescript-paths` to resolve TypeScript path aliases. It includes a runnable `rollup.config.js` and outlines the necessary `tsconfig.json` and source file structure to illustrate path resolution for `@utils` and `@components` aliases, assuming TypeScript transpilation (e.g., for declaration files) might occur in a separate step.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}