diff --git a/.changeset/lazy-entry-eliminated-importers.md b/.changeset/lazy-entry-eliminated-importers.md new file mode 100644 index 0000000..ed4181f --- /dev/null +++ b/.changeset/lazy-entry-eliminated-importers.md @@ -0,0 +1,5 @@ +--- +'vite-plugin-solid': patch +--- + +Reclassify emitted lazy facade chunks even when their importers are eliminated from the final bundle. Emitted chunk references are now retained so lazy facades can be identified without relying on a surviving `dynamicImports` edge. diff --git a/examples/vite-8/src/App.tsx b/examples/vite-8/src/App.tsx index 84029bf..1454b4a 100644 --- a/examples/vite-8/src/App.tsx +++ b/examples/vite-8/src/App.tsx @@ -1,7 +1,6 @@ import { onSettled } from "solid-js"; import { CounterProvider, useCounter } from "./CounterContext"; - -const title = 'Counter'; +import { title } from './UnusedLazyImporter'; function Count() { const counter = useCounter(); diff --git a/examples/vite-8/src/UnusedLazy.tsx b/examples/vite-8/src/UnusedLazy.tsx new file mode 100644 index 0000000..c87182e --- /dev/null +++ b/examples/vite-8/src/UnusedLazy.tsx @@ -0,0 +1,3 @@ +export default function UnusedLazy() { + return
This lazy component should be removed from the application.
; +} diff --git a/examples/vite-8/src/UnusedLazyImporter.ts b/examples/vite-8/src/UnusedLazyImporter.ts new file mode 100644 index 0000000..7266798 --- /dev/null +++ b/examples/vite-8/src/UnusedLazyImporter.ts @@ -0,0 +1,9 @@ +import { lazy } from 'solid-js'; + +export const title = 'Counter'; + +export class UnusedLazyImporter { + mount() { + return lazy(() => import('./UnusedLazy')); + } +} diff --git a/examples/vite-8/vite.config.ts b/examples/vite-8/vite.config.ts index 6128d7d..6ecabe7 100644 --- a/examples/vite-8/vite.config.ts +++ b/examples/vite-8/vite.config.ts @@ -3,6 +3,33 @@ import solidPlugin from 'vite-plugin-solid'; export default defineConfig({ plugins: [ - solidPlugin({ compiler: 'native' }), + { + name: 'simulate-eliminated-lazy-importer', + enforce: 'pre', + generateBundle(_options, bundle) { + for (const output of Object.values(bundle)) { + if (output.type === 'chunk') { + output.dynamicImports = []; + } + } + }, + }, + solidPlugin({ compiler: 'native', ssr: true }), + { + name: 'assert-single-entry', + enforce: 'post', + generateBundle(_options, bundle) { + const entries = Object.values(bundle).filter( + (output) => output.type === 'chunk' && output.isEntry, + ); + if (entries.length !== 1) { + throw new Error( + `Expected one entry chunk, received: ${entries + .map((entry) => entry.fileName) + .join(', ')}`, + ); + } + }, + }, ], -}); \ No newline at end of file +}); diff --git a/src/index.ts b/src/index.ts index 0aecc77..705df6e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -310,6 +310,10 @@ export default function solidPlugin(options: Partial