@@ -31,33 +31,6 @@ export default {
3131- ` components ` are classes found in files that contain the configured decorator (default: ` @Component ` ).
3232- ` activator ` is set to the default export of the configured activator module, if provided.
3333
34- ## Usage with Rollup
35-
36- ``` javascript
37- // rollup.config.mjs
38- import pandinoBundle from ' @pandino/rollup-bundle-plugin' ;
39-
40- export default {
41- input: ' pandino:bundle' , // or import 'pandino:bundle' in your code
42- plugins: [
43- pandinoBundle ({
44- // rootDir: process.cwd(),
45- // include: ['**/*.{ts,tsx,js,jsx}'],
46- // exclude: ['**/node_modules/**', '**/dist/**', '**/build/**'],
47- // componentsDecorator: 'Component',
48- // activator: 'src/Activator.ts',
49- // outputFile: 'pandino/bundle.js',
50- }),
51- ],
52- output: {
53- dir: ' dist' ,
54- format: ' es' ,
55- },
56- };
57- ```
58-
59- You can also omit ` input: 'pandino:bundle' ` and rely on the plugin to emit the chunk named by ` outputFile ` .
60-
6134## Usage with Vite
6235
6336``` typescript
@@ -66,25 +39,50 @@ import { defineConfig } from 'vite';
6639import pandinoBundle from ' @pandino/rollup-plugin-bundle' ;
6740
6841export default defineConfig ({
42+ // ...
6943 plugins: [
70- pandinoBundle ({ activator: ' src/Activator.ts' }),
44+ pandinoBundle ({
45+ virtualId: ' pandino:bundle:alpha' ,
46+ include: [' src/bundles/alpha/**/*.{ts,tsx}' ],
47+ activator: ' src/bundles/alpha/activator.ts' ,
48+ headers: {
49+ bundleSymbolicName: ` ${packageJson .name }.alpha ` ,
50+ bundleVersion: packageJson .version ,
51+ bundleDescription: ' Alpha example bundle' ,
52+ },
53+ }),
7154 ],
72- build: {
73- rollupOptions: {
74- // optionally add as an entry
75- input: ' pandino:bundle' ,
76- },
77- },
7855});
7956```
8057
58+ > Every ` pandinoBundle() ` call creates a separate bundle. You can call it multiple times with different options if needed.
59+
8160Then in your app you can import:
8261
83- ``` typescript
84- import bundle from ' pandino:bundle' ;
85- // bundle.headers, bundle.activator, bundle.components
62+ ``` typescript jsx
63+ import { type FC , StrictMode } from ' react' ;
64+ import { createRoot } from ' react-dom/client' ;
65+ import { PandinoProvider } from ' @pandino/react-hooks' ;
66+
67+ const Root: FC = () => {
68+ return (
69+ < PandinoProvider bundles = {[import (' pandino:bundle:alpha' ), /* ... */ ]}>
70+ {/* ... */ }
71+ </PandinoProvider>
72+ );
73+ };
74+
75+ const rootElement = document.getElementById('root')!;
76+
77+ createRoot(rootElement).render(
78+ <StrictMode>
79+ <Root />
80+ </StrictMode>,
81+ );
8682```
8783
84+ The `virtualId` option is only necessary if you want to import the bundle module directly. If you only want the emitted chunk, you can omit it.
85+
8886## Options
8987
9088- **include**: string | string []
0 commit comments