A esbuild plugin to support path aliases similar to webpack's resolve.alias. Current version 1.0.7, limited release history. It allows developers to define custom path mappings (e.g., '@' -> './app/component') so that import paths in source code can be shortened. The plugin requires esbuild as a peer dependency and expects absolute paths in alias definitions. Compared to alternatives like `esbuild-alias`, this plugin is minimal and focused, but lacks advanced features like tsconfig path resolution. It uses the `onResolve` hook and Node.js path module for resolution, and works with both ESM and CJS builds.
npm install esbuild-plugin-path-aliasVerified import paths — ran on the pinned version, not inferred.
Shows how to set up esbuild-plugin-path-alias with two aliases, then import using the alias.
Use path.resolve() to convert relative paths to absolute.
Consider using esbuild-plugin-tsconfig-paths if you need tsconfig-based aliases.
Ensure your esbuild setup supports CJS plugins, or use an alternative that provides ESM exports.
Verify alias definitions and import statements match exactly, including path separators (use forward slashes).
Use path.resolve() to make the alias value absolute, e.g., path.resolve(__dirname, 'src/components').
Use import aliasPlugin from 'esbuild-plugin-path-alias' instead of destructuring.
Define alias for '@components' or ensure the import path matches exactly: import from '@/Header'.