An esbuild plugin that automatically resolves asset paths relative to the importing JavaScript file at runtime, eliminating the need for a fixed public path. Version 1.4.0 (latest) ships TypeScript types, supports Node >=16, and is maintained as part of the Piral CLI ecosystem. Unlike alternative solutions that require build-time public path configuration, this plugin enables micro frontend setups where each asset is served from a different path by rewriting asset imports to use runtime-determined paths.
npm install esbuild-auto-path-pluginNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Sets up esbuild with autoPathPlugin to bundle and resolve asset paths at runtime using import.meta.url.
Switch project to ESM (type: 'module' in package.json) or use dynamic import. Alternatively, use older version 0.15.x if CJS support is required.
If you rely on the old defaults, explicitly pass defaultExtensions: ['.png', '.svg', '.jpg', '.jpeg', '.webp', '.mp4', '.mp3', '.ogg', '.wav', '.ogv', '.wasm', '.gif'].
Set format: 'esm' in esbuild build options, or avoid using this plugin with CommonJS output.
Ensure assets you want to auto-path are loaded with loader: { '.ext': 'file' } in esbuild config.Run 'npm install esbuild-auto-path-plugin --save-dev'. If your project is CJS, use 'const { autoPathPlugin } = await import('esbuild-auto-path-plugin');'.Use named import: import { autoPathPlugin } from 'esbuild-auto-path-plugin';Call autoPathPlugin() in the plugins array: plugins: [autoPathPlugin()].