@rollup/plugin-alias

Rollup plugin for defining and resolving import aliases, swapping brittle relative paths for clean, refactor-safe module names.

Library
npm
v6.0.0
3,757stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
47/100Fair
Development Activity16
Maintenance0
Community72
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
73/100Good
Architecture82
Code Quality78
Innovation45
Learning Curve85

@rollup/plugin-alias lets a Rollup build treat one string as a stand-in for another module specifier, so import batman from '../../../batman' can become import batman from 'batman'. It mirrors the resolve.alias behavior familiar from Webpack: entries are declared as either a plain object map or an array of { find, replacement } pairs, checked in order, with find allowed to be a plain string prefix or a full regular expression for pattern-based rewrites (e.g. swapping file extensions across an entire import graph).

The plugin is intentionally small and hooks into exactly one place in Rollup’s pipeline: resolveId. When an importee matches an alias entry, it rewrites the id and either resolves it itself, defers to a custom resolver supplied per-entry or globally, or falls back to Rollup’s own this.resolve. That single-purpose design is what makes it composable — teams pair it with @rollup/plugin-node-resolve to alias short names to real filesystem paths, or with framework tooling (Vite, and other Rollup-based bundlers) that needs deterministic path rewriting without a full module-resolution algorithm of its own. It is maintained as one package inside the rollup/plugins monorepo, which houses the full family of official Rollup plugins.

What You Get

  • Object or array syntax for declaring aliases, with array format supporting per-entry custom resolvers
  • Regular-expression matching for partial replacements, such as rewriting file extensions across an entire import graph
  • Order-sensitive matching — the first alias entry that matches an importee wins
  • A customResolver hook (function or object with resolveId/buildStart) to delegate resolution to another plugin instead of Rollup’s default resolver
  • Automatic fallback to Rollup’s built-in resolver via this.resolve with skipSelf: true when no custom resolver is supplied
  • A build-time warning when a rewritten id isn’t absolute and wasn’t resolved by another plugin, flagging likely duplicate-module bugs early

Common Use Cases

  • Replacing deep relative imports like ../../../utils with a flat alias such as utils across a large codebase
  • Aliasing a versioned or renamed dependency (e.g. batman-1.0.0 to ./joker-1.5.0) during a migration without editing every import
  • Using regex aliases to redirect all imports of one file extension to another, such as legacy AMD-style i18n! loader syntax to plain .js imports
  • Combining with @rollup/plugin-node-resolve as the customResolver so aliased paths still go through Node’s module resolution algorithm

Under The Hood

Architecture The plugin implements a single Rollup resolveId hook and nothing else. Alias entries (object map or array form) are normalized up front by getEntries into a flat list of resolved alias records, each carrying its own resolver function when a custom resolver applies. On every resolution request, matches() checks the importee against each entry’s find value in declaration order — a string prefix/exact check or a regex test — and the first hit wins. A matched entry’s id is rewritten via string replace, then handed to a custom resolver if one exists, or resolved through Rollup’s own this.resolve with skipSelf: true, falling back to returning the rewritten id directly with a warning if it isn’t absolute and nothing else claimed it. The whole surface area is contained in one module, so the failure modes (an unmatched alias, an unresolved rewritten path) are easy to reason about end to end.

Tech Stack The package is authored in TypeScript, compiled with tsc, and ships as ESM-only (type: module, a single import export condition plus generated .d.ts types) — there’s no bundling step for the plugin itself. It sits inside the rollup/plugins pnpm workspace alongside the rest of the official plugin family, sharing a base tsconfig, ESLint config (eslint-config-rollup), and Prettier setup enforced repo-wide via Husky and lint-staged pre-commit hooks. Its only runtime dependency is Node’s own path module; Rollup itself is an optional peer dependency, and @rollup/plugin-node-resolve shows up only as a dev dependency used in tests and docs as the recommended customResolver pairing.

Code Quality Tests run under Vitest and exercise the plugin through actual Rollup builds rather than mocking the resolver pipeline — a small in-memory resolveId/load harness feeds real import graphs through rollup() and asserts on the resolved ids, covering object and array entry formats, regex aliases, and custom resolvers. Types are deliberately narrowed (a MapToFunction helper excludes the loose global Function type in favor of Rollup’s actual resolveId signature), which keeps the public RollupAliasOptions surface honest. Lint and type-check both run in CI (ci:lint, ci:test) ahead of publish, and unresolved-path situations surface as build warnings rather than being swallowed silently.

API Design The public API is intentionally minimal: one default export taking a single options object with just entries and an optional customResolver, closely mirroring Webpack’s familiar resolve.alias shape so the mental model transfers without new concepts to learn. Getting started requires no boilerplate beyond adding the plugin to a Rollup config’s plugins array. The tradeoff of that narrow surface is that it deliberately doesn’t try to out-innovate the well-established alias-resolution pattern it borrows from other bundlers — its value is in doing that one job simply and predictably.

Used by 140 apps in this directory

TypeScript
72%
AGPL 3.0

APITable

Low Code Platforms · Databases

15,588

API-first collaborative spreadsheet-database platform that auto-generates REST APIs and lets teams build internal tools, CRMs, and dashboards without code.

View details
74
Repo Health
77
Technical
60
Dependency
Built with
TypeScript72%
Java22%
Updated yesterday
TypeScript
72%
AGPL 3.0

APITable

Low Code Platforms · Databases

15,588

API-first collaborative spreadsheet-database platform that auto-generates REST APIs and lets teams build internal tools, CRMs, and dashboards without code.

View details
74
Repo Health
77
Technical
60
Dependency
Built with
TypeScript72%
Java22%
Updated yesterday
TypeScript
72%
AGPL 3.0

APITable

Low Code Platforms · Databases

15,588

API-first collaborative spreadsheet-database platform that auto-generates REST APIs and lets teams build internal tools, CRMs, and dashboards without code.

View details
74
Repo Health
77
Technical
60
Dependency
Built with
TypeScript72%
Java22%
Updated yesterday
TypeScript
63%
MIT

ALTCHA

Security

2,737

A self-hosted, privacy-first CAPTCHA alternative that uses memory-hard proof-of-work to stop bots without cookies, tracking, or third-party APIs.

View details
72
Repo Health
79
Technical
75
Dependency
Built with
TypeScript63%
Svelte29%
Updated yesterday
TypeScript
88%
MIT

Amical

Note Taking · AI Assistants

1,522

Local-first AI dictation that understands your active app — private, offline, and built for speed.

View details
81
Repo Health
82
Technical
67
Dependency
Built with
TypeScript88%
Updated 2 days ago
TypeScript
68%
Apache 2.0

Appsmith

Developer Tools · Automation · No Code Platforms

40,825

Open-source low-code platform to build admin panels, dashboards, and internal tools connected to any database or API.

View details
93
Repo Health
79
Technical
66
Dependency
Built with
TypeScript68%
Java21%
Updated 3 days ago
TypeScript
68%
Apache 2.0

Appsmith

Developer Tools · Automation · No Code Platforms

40,825

Open-source low-code platform to build admin panels, dashboards, and internal tools connected to any database or API.

View details
93
Repo Health
79
Technical
66
Dependency
Built with
TypeScript68%
Java21%
Updated 3 days ago
Python
56%
Other

authentik

Authentication · Security

25,385

The self-hosted Identity Provider that replaces Okta, Auth0, and Entra ID with a unified SSO platform supporting SAML, OAuth2/OIDC, LDAP, RADIUS, and WebAuthn.

View details
92
Repo Health
81
Technical
66
Dependency
Built with
Python56%
TypeScript34%
Updated yesterday
Python
56%
Other

authentik

Authentication · Security

25,385

The self-hosted Identity Provider that replaces Okta, Auth0, and Entra ID with a unified SSO platform supporting SAML, OAuth2/OIDC, LDAP, RADIUS, and WebAuthn.

View details
92
Repo Health
81
Technical
66
Dependency
Built with
Python56%
TypeScript34%
Updated yesterday

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search