Registry / web-framework / esbuild-svelte-paths

esbuild-svelte-paths

JSON →
library0.1.4jsnpmunverified

ESBuild plugin that resolves shortcuted paths for Svelte components, allowing imports without '.svelte' extension and folder/file name matching. Current stable version is 0.1.4, released in May 2022. It respects path aliases from tsconfig/jsconfig. Differentiators: specifically for esbuild (not webpack/vite), requires capital-letter last path segment to trigger resolution, and supports custom extensions for other frameworks like Malina.

npm install esbuild-svelte-paths
INSTALL
IMPORT
SIG · ESBUILD-SVELTE-PAT
E
esbuild-svelte-paths
web-frameworkjavascriptv0.1.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

sveltePaths
import { sveltePaths } from 'esbuild-svelte-paths'
import sveltePaths from 'esbuild-svelte-paths'
Named export, not default.
sveltePaths (require)
const { sveltePaths } = require('esbuild-svelte-paths')
const sveltePaths = require('esbuild-svelte-paths')
CommonJS require must destructure the named export.
Plugin (as ESBuild plugin object)
const { sveltePaths } = require('esbuild-svelte-paths'); plugins: [sveltePaths()]
import sveltePaths from 'esbuild-svelte-paths'; plugins: [sveltePaths]
sveltePaths is a function that must be called to create the plugin instance.

Shows how to install and configure the plugin in an esbuild script, placing it before the Svelte compiler plugin.

const { sveltePaths } = require('esbuild-svelte-paths'); const sveltePlugin = require('esbuild-svelte'); require('esbuild').build({ entryPoints: ['src/main.js'], bundle: true, outfile: 'public/bundle.js', plugins: [ sveltePaths(), sveltePlugin() ] }).catch(() => process.exit(1));
Debug
Known issues
gotchaPlugin must be placed before any Svelte compiler plugin in the plugins array, otherwise resolution may fail.
fix
Ensure the order: sveltePaths() first, then sveltePlugin().
affects: >=0.0.0
gotchaShortcut only applies when the last path segment starts with a capital letter. Lowercase imports are ignored and treated normally.
fix
Use capital letter for the component name in the import path, e.g., import Button from './Button'.
affects: >=0.1.0
gotchaIDE features like ctrl+click and autocomplete are lost for shortcuted imports; the import path is virtual and not resolved by the IDE.
fix
Use explicit full paths if you need IDE navigation support.
affects: >=0.0.0
Errors
Common errors & fixes
Plugin must be placed before other plugins in esbuild
Plugin order is not correct: sveltePaths() is not first or missing.
fix
Move sveltePaths() before any Svelte compiler plugin in the plugins array.
Cannot find module './component' (unexpected)
Import path does not start with capital letter, so shortcut is not applied and esbuild tries to resolve the file without .svelte extension.
fix
Ensure the last segment of the import path starts with a capital letter, e.g., './Component'.
The plugin does not work with bundled esbuild
Esbuild is used programmatically with bundle option but plugin is not installed or configured.
fix
Install esbuild-svelte-paths and add it to the plugins array before the Svelte plugin.
Upgrade
Version history
0.1.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
esbuild-svelte-paths — npm install esbuild-svelte-paths · libregistry