diff --git a/website/MODULE_API.md b/website/MODULE_API.md index aed2c49..de6c820 100644 --- a/website/MODULE_API.md +++ b/website/MODULE_API.md @@ -663,27 +663,33 @@ owns the paths it calls, which is correct: it owns the routes at the other end. ### 3.6 Vite library-mode build -The module's `vite.config.js`, and the four externals are the whole contract: +The module's `vite.config.js`, and the shared-dependency aliases are the whole contract: ```js export default defineConfig({ - plugins: [react()], + plugins: [react(), assertSharedNotBundled()], + resolve: { + // ARRAY form with ANCHORED regexes. The object form does PREFIX matching, so + // a `react` key silently also rewrites `react/jsx-runtime`. + alias: [ + { find: /^react$/, replacement: shim('react') }, + { find: /^react\/jsx-runtime$/, replacement: shim('jsx-runtime') }, + { find: /^react\/jsx-dev-runtime$/, replacement: shim('jsx-runtime') }, + { find: /^react-dom$/, replacement: shim('react-dom') }, + { find: /^react-dom\/client$/, replacement: shim('react-dom') }, + { find: /^react-router-dom$/, replacement: shim('react-router-dom') }, + ], + }, build: { lib: { entry: 'src/entry.jsx', formats: ['es'], fileName: () => 'entry.js' }, outDir: 'dist', modulePreload: { polyfill: false }, // same reason as core: no inline bootstrap under CSP - rollupOptions: { - external: ['react', 'react-dom', 'react-dom/client', 'react-router-dom'], - output: { paths: { /* rewritten to window.__rg by the shim below */ } }, - }, + rollupOptions: { external: [] }, // deliberately empty — see below }, }) ``` -Rollup's `external` alone emits bare `import 'react'` specifiers, which the browser cannot resolve -without an import map — and CSP forbids the inline `