Skip to content

Commit 17052c1

Browse files
feat!: vite 8 / rolldown compatibility (#76)
* chore(deps): upgrade vite to v8.0.16 * chore(deps): install @eik/common * test: update snapshots * refactor(plugin): inline import-map logic, drop @eik/rollup-plugin * chore(deps): uninstall @eik/rollup-plugin * feat(plugin)!: convert external require calls to ESM facades for Rolldown Adds handling for require() calls of mapped specifiers under Vite 8 / Rolldown. Rolldown no longer auto-converts external require() to ESM import (see vite.dev/guide/migration#require-calls-for-externalized-modules), so the plugin now routes each require() to a virtual ESM facade that imports the URL, letting the bundler's CJS interop wrap it at the call site. BREAKING CHANGE: targets Vite 8+ as the supported runtime. Output may include one additional virtual chunk per require()-mapped specifier. * test(plugin): cover require() of mapped specifier test(fixtures): add cjs fixture for require() tests * test(plugin): cover mixed import + require for the same specifier test(fixtures): add mixed import + require fixture * test(plugin): cover require() of unmapped dependency * docs(readme): document Vite 8 / Rolldown require handling
1 parent d4541ae commit 17052c1

10 files changed

Lines changed: 790 additions & 774 deletions

File tree

README.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[Vite](https://vite.dev/) plugin for [build-time import mapping with Eik](https://eik.dev/docs/guides/vite).
44

5-
This is a small wrapper around the [Rollup plugin](https://github.com/eik-lib/rollup-plugin) to make it slightly more ergonomic to use in Vite.
5+
Resolves bare import specifiers in your client bundle to URLs hosted on an Eik server, so shared dependencies (React, lit, etc.) load from one place across apps instead of being bundled into each one.
66

77
## Installation
88

@@ -24,7 +24,7 @@ export default defineConfig({
2424
// Turn off the asset hashes. Stable file names
2525
// make it easier to use the Eik node client:
2626
// https://github.com/eik-lib/node-client
27-
// Publishinig a new version on Eik gives a
27+
// Publishing a new version on Eik gives a
2828
// unique URL, no hash needed.
2929
assetFileNames: "[name].[ext]",
3030
entryFileNames: "[name].js",
@@ -37,5 +37,16 @@ export default defineConfig({
3737

3838
## Options
3939

40-
The options you can give to `eik()` are the same as for the Rollup plugin.
41-
Refer to [the Rollup plugin documentation](https://github.com/eik-lib/rollup-plugin?tab=readme-ov-file#options) to see what you can do.
40+
| Option | Type | Default | Description |
41+
| ------ | -------------------------- | ---------------- | --------------------------------------------------------------------------------- |
42+
| `path` | `string` | `process.cwd()` | Path to `eik.json`. |
43+
| `urls` | `string[]` | `[]` | URLs to import maps hosted on an Eik server. Takes precedence over `eik.json`. |
44+
| `maps` | `ImportMap \| ImportMap[]` | `[]` | Inline import maps. Takes precedence over `urls` and `eik.json`. |
45+
46+
An `ImportMap` is `{ imports: Record<string, string> }`.
47+
48+
## Vite 8 / Rolldown
49+
50+
Static `import` statements of mapped specifiers are rewritten to external URL imports. `require()` calls of mapped specifiers are routed through a virtual ESM facade so the bundler's CJS interop wraps them at the call site.
51+
52+
Without the facade, Rolldown would leave a literal `require("<url>")` in the output bundle, which throws in the browser. See the [Vite 8 migration note](https://vite.dev/guide/migration#require-calls-for-externalized-modules) for background.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const { LitElement } = require("lit-element");
2+
3+
module.exports = class Inner extends LitElement {
4+
render(world) {
5+
return world;
6+
}
7+
};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const { LitElement } = require("lit-element");
2+
module.exports = class Inner extends LitElement {};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { LitElement } from "lit-element";
2+
import inner from "./inner.cjs";
3+
4+
export default class Outer extends LitElement {
5+
render() {
6+
return inner;
7+
}
8+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const unmapped = require("some-unmapped-package");
2+
3+
module.exports = unmapped;

0 commit comments

Comments
 (0)