Registry / web-framework / rollup-plugin-base-url

rollup-plugin-base-url

JSON →
library0.0.2jsnpmunverified

A Rollup plugin that rewrites dynamic (and optionally static) import paths to use an absolute base URL, such as '/' or '/forum'. This prevents chunk loading failures on sub-routes (e.g., /login loads chunks from the wrong path). Version 0.0.2 is the current release. It avoids AST parsing for performance, doing a naive string replacement of chunk paths. No known release cadence. Differentiators: lightweight, simple, no AST overhead, compatible with plugins like rollup-plugin-hoist-import-deps. Alternatives (e.g., @rollup/plugin-url) target assets, not imports.

npm install rollup-plugin-base-url
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-BASE
R
rollup-plugin-base-url
web-frameworkjavascriptv0.0.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

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

baseUrl
import { baseUrl } from 'rollup-plugin-base-url'
const baseUrl = require('rollup-plugin-base-url')
Package is ESM-only; require() will fail because package.json has no 'main' or 'exports' for CJS.
default export
import { baseUrl } from 'rollup-plugin-base-url'
import baseUrl from 'rollup-plugin-base-url'
There is no default export. Only the named export 'baseUrl' exists.
baseUrl (options)
baseUrl({ url: '/forum', staticImports: true })
baseUrl('/forum', true)
The plugin takes a single options object; positional arguments are not supported.

Basic Rollup config using baseUrl plugin to serve dynamic imports from '/' root, preventing route-specific loading errors.

// rollup.config.js import { baseUrl } from 'rollup-plugin-base-url'; export default { input: 'src/index.js', output: { dir: 'dist', format: 'es', entryFileNames: '[name]-[hash].js', chunkFileNames: '[name]-[hash].js', }, plugins: [ baseUrl({ url: '/', staticImports: false, }), ], };
Debug
Known issues
gotchaDoes not parse AST; uses naive string replacement of import paths. May incorrectly replace strings in comments, strings, or variable names that match the chunk pattern.
fix
Avoid using file names or imports that contain patterns like './some-chunk-hash.js' in string literals or comments.
affects: >=0.0.0
gotchaOnly rewrites imports that match the exact output chunk pattern; non-standard chunk file names or custom hash functions may not be recognized.
fix
Ensure output.chunkFileNames uses the default '[name]-[hash].js' pattern, or adapt plugin logic.
affects: >=0.0.0
breakingVersion 0.0.2 is the only release; no breaking changes yet, but be aware of possible future changes.
fix
None needed.
affects: <0.0.2
deprecatedPackage is experimental and may be abandoned; no recent updates.
fix
Consider migrating to a more maintained alternative if needed.
affects: >=0.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module
Using require('rollup-plugin-base-url') in a CommonJS context.
fix
Change to import { baseUrl } from 'rollup-plugin-base-url' and ensure your project is ESM (e.g., use 'type': 'module' in package.json or .mjs extension).
TypeError: (0 , _baseUrl.baseUrl) is not a function
Attempting to call baseUrl() with incorrect arguments, e.g., baseUrl('/forum', true) instead of baseUrl({url: '/forum', staticImports: true}).
fix
Invoke baseUrl with a single options object: baseUrl({ url: '/forum', staticImports: true }).
Error: Could not resolve import ... in file ...
Plugin didn't rewrite the import path correctly, possibly because the chunk name doesn't match the expected pattern or staticImports is false but a static import is present.
fix
Check that output.chunkFileNames uses '[name]-[hash].js' pattern. If using static imports, set staticImports: true.
Upgrade
Version history
0.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
rollup-plugin-base-url — npm install rollup-plugin-base-url · libregistry