Registry / web-framework / esbuild-svelte-inertia

esbuild-svelte-inertia

JSON →
library0.0.5jsnpmunverified

A tiny esbuild plugin (v0.0.5, updated Dec 2022, no regular release schedule) that enables importing Svelte page components via glob patterns for use with Inertia.js. It removes the need for manual page registration by resolving dynamic imports. Intended for esbuild-based Svelte + Inertia projects. Minimal and focused, but unmaintained since initial release.

npm install esbuild-svelte-inertia
INSTALL
IMPORT
SIG · ESBUILD-SVELTE-INE
E
esbuild-svelte-inertia
web-frameworkjavascriptv0.0.5
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.

default export
const svelteInertiaPlugin = require('esbuild-svelte-inertia')
import svelteInertiaPlugin from 'esbuild-svelte-inertia'
Package only provides CommonJS; no ESM export. Use require() in Node.js or configure bundler to handle CJS.
pages import
import * as pages from './Pages/**/*'
import pages from './Pages/**/*'
The glob import must use namespace import syntax. Also ensure the glob pattern is supported by esbuild (no external plugin).
plugin usage
plugins: [sveltePlugin(), svelteInertiaPlugin()]
plugins: [svelteInertiaPlugin, sveltePlugin]
The plugin is a function that must be called (with no arguments). Pair with the official svelte plugin.

Minimal setup: esbuild config with both svelte and inertia plugins, then import pages via glob for Inertia resolve.

// esbuild.config.js const esbuild = require('esbuild'); const sveltePlugin = require('esbuild-svelte'); const svelteInertiaPlugin = require('esbuild-svelte-inertia'); // Ensure your svelte.config.js has the inertiakit adapter or handle SPA mode async function build() { await esbuild.build({ entryPoints: ['src/main.js'], bundle: true, outdir: 'public/build', plugins: [sveltePlugin(), svelteInertiaPlugin()], }); } build().catch(() => process.exit(1)); // Example main.js using Inertia import { createInertiaApp } from '@inertiajs/inertia-svelte'; import * as pages from './src/Pages/**/*'; createInertiaApp({ resolve: name => pages[name.replace('/', '')], setup({ el, App, props }) { new App({ target: el, props }); }, });
Debug
Known issues
gotchaThe glob import pattern './Pages/**/*' may not work as expected if your project is bundled with esbuild without the 'copy' plugin for static files. Only .svelte files are picked up.
fix
Ensure all Svelte page components have .svelte extension and the pattern matches directory structure exactly.
affects: >=0.0.0
gotchaPlugin is CommonJS only; importing via ESM 'import' will cause 'require is not defined' error if Node ES modules mode is used.
fix
Use require() in CommonJS context, or configure your project to convert CJS to ESM (e.g., esbuild's --format=esm with CJS shims).
affects: >=0.0.0
gotchaThe plugin does not handle nested page directories reliably; the replace('/','') may break if pages have subfolders (e.g., 'Admin/Dashboard').
fix
Modify resolve: name => pages['./' + name.replace('./Pages/', '').replace('.svelte', '')] or use a custom resolver.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: require(...) is not a function
Using ESM import syntax for a CJS-only module.
fix
Use 'const svelteInertiaPlugin = require("esbuild-svelte-inertia")' instead of import.
Error: Cannot find module './Pages/**/*'
Glob pattern not resolved; esbuild needs the plugin to handle the glob import.
fix
Add 'svelteInertiaPlugin()' to the plugins array. Also ensure the directory './Pages' exists relative to the entry point.
TypeError: pages[name.replace(...)] is undefined
Page name does not match key in the imported pages object (likely due to path prefix or extension).
fix
Check the exact keys: log 'pages' to see the shape. Common fix: use 'name.replace('/', '').replace('.svelte', '')'.
Upgrade
Version history
0.0.5latest on npm
Audit
Dependencies
esbuildrequiredpeer dependency required for plugin to work
Agent activity
2 hits · last 30 days
node
2
Resources
esbuild-svelte-inertia — npm install esbuild-svelte-inertia · libregistry