@nsxbet/admin-sdk 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHECKLIST.md +93 -4
- package/README.md +111 -3
- package/dist/vite/config.d.ts +44 -11
- package/dist/vite/config.d.ts.map +1 -1
- package/dist/vite/config.js +70 -28
- package/dist/vite/index.d.ts +1 -1
- package/dist/vite/index.d.ts.map +1 -1
- package/dist/vite/index.js +1 -1
- package/package.json +5 -1
package/CHECKLIST.md
CHANGED
|
@@ -67,7 +67,7 @@ Expected structure:
|
|
|
67
67
|
|
|
68
68
|
### Dev Dependencies
|
|
69
69
|
|
|
70
|
-
- [ ] `@vitejs/plugin-react`
|
|
70
|
+
- [ ] React plugin — either `@vitejs/plugin-react` `^4.2.1` OR `@vitejs/plugin-react-swc` `^3.0.0` (Lovable default)
|
|
71
71
|
- [ ] `vite` — `^5.0.8`
|
|
72
72
|
- [ ] `typescript` — `^5.2.2`
|
|
73
73
|
- [ ] `tailwindcss` — `^3.4.0`
|
|
@@ -77,10 +77,10 @@ Expected structure:
|
|
|
77
77
|
|
|
78
78
|
## Vite Configuration
|
|
79
79
|
|
|
80
|
-
- [ ]
|
|
81
|
-
- [ ] Imports and uses
|
|
80
|
+
- [ ] Uses `defineModuleConfig` from `@nsxbet/admin-sdk/vite` OR spreads `adminModule()` into an existing Vite config
|
|
81
|
+
- [ ] Imports and uses a React plugin (`@vitejs/plugin-react` or `@vitejs/plugin-react-swc`)
|
|
82
82
|
|
|
83
|
-
Expected:
|
|
83
|
+
Expected (option A — full config):
|
|
84
84
|
|
|
85
85
|
```typescript
|
|
86
86
|
import { defineModuleConfig } from "@nsxbet/admin-sdk/vite";
|
|
@@ -92,6 +92,18 @@ export default defineModuleConfig({
|
|
|
92
92
|
});
|
|
93
93
|
```
|
|
94
94
|
|
|
95
|
+
Expected (option B — composable plugin for Lovable / existing config):
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
import { defineConfig } from "vite";
|
|
99
|
+
import react from "@vitejs/plugin-react-swc";
|
|
100
|
+
import { adminModule } from "@nsxbet/admin-sdk/vite";
|
|
101
|
+
|
|
102
|
+
export default defineConfig({
|
|
103
|
+
plugins: [react(), ...adminModule()],
|
|
104
|
+
});
|
|
105
|
+
```
|
|
106
|
+
|
|
95
107
|
## Tailwind Configuration
|
|
96
108
|
|
|
97
109
|
- [ ] Imports `withAdminSdk` from `@nsxbet/admin-sdk/tailwind`
|
|
@@ -201,6 +213,83 @@ function MyComponent() {
|
|
|
201
213
|
}
|
|
202
214
|
```
|
|
203
215
|
|
|
216
|
+
## Lovable Projects (additional guidance)
|
|
217
|
+
|
|
218
|
+
If your module was scaffolded by Lovable, the following differences apply:
|
|
219
|
+
|
|
220
|
+
- [ ] `vite.config.ts` uses `adminModule()` spread into the existing plugins array (option B above), NOT `defineModuleConfig`
|
|
221
|
+
- [ ] React plugin is `@vitejs/plugin-react-swc` (Lovable default) — this is supported
|
|
222
|
+
- [ ] `index.html` entry point references `/src/main.tsx` (Lovable default) — this serves as the standalone dev entry
|
|
223
|
+
- [ ] `src/main.tsx` wraps your App with `AdminShell` (same role as `src/standalone.tsx` in non-Lovable modules)
|
|
224
|
+
- [ ] `src/spa.tsx` still required — `export default App` for shell mode
|
|
225
|
+
- [ ] `admin.module.json` still required at project root
|
|
226
|
+
- [ ] `module.manifest.json` is auto-generated at build time by `adminModule()` — do NOT manually copy `admin.module.json` to `dist/`
|
|
227
|
+
- [ ] Lovable's existing `server`, `resolve.alias`, and plugin settings are preserved — `adminModule()` only affects `vite build`
|
|
228
|
+
- [ ] Build script can be `"vite build"` (Lovable default) or `"tsc && vite build"` — both work
|
|
229
|
+
|
|
230
|
+
Expected `vite.config.ts` for Lovable:
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
import { defineConfig } from "vite";
|
|
234
|
+
import react from "@vitejs/plugin-react-swc";
|
|
235
|
+
import path from "path";
|
|
236
|
+
import { componentTagger } from "lovable-tagger";
|
|
237
|
+
import { adminModule } from "@nsxbet/admin-sdk/vite";
|
|
238
|
+
|
|
239
|
+
export default defineConfig(({ mode }) => ({
|
|
240
|
+
server: {
|
|
241
|
+
host: "::",
|
|
242
|
+
port: 8080,
|
|
243
|
+
hmr: { overlay: false },
|
|
244
|
+
},
|
|
245
|
+
plugins: [
|
|
246
|
+
react(),
|
|
247
|
+
mode === "development" && componentTagger(),
|
|
248
|
+
...adminModule(),
|
|
249
|
+
].filter(Boolean),
|
|
250
|
+
resolve: {
|
|
251
|
+
alias: {
|
|
252
|
+
"@": path.resolve(__dirname, "./src"),
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
}));
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
Expected `src/main.tsx` for Lovable (standalone dev entry):
|
|
259
|
+
|
|
260
|
+
```tsx
|
|
261
|
+
import React from "react";
|
|
262
|
+
import ReactDOM from "react-dom/client";
|
|
263
|
+
import {
|
|
264
|
+
AdminShell,
|
|
265
|
+
createInMemoryAuthClient,
|
|
266
|
+
createMockUsersFromRoles,
|
|
267
|
+
} from "@nsxbet/admin-sdk";
|
|
268
|
+
import type { AdminModuleManifest } from "@nsxbet/admin-sdk";
|
|
269
|
+
import { App } from "./App";
|
|
270
|
+
import manifest from "../admin.module.json";
|
|
271
|
+
import "./index.css";
|
|
272
|
+
|
|
273
|
+
const moduleManifest = manifest as AdminModuleManifest;
|
|
274
|
+
|
|
275
|
+
const mockUsers = createMockUsersFromRoles({
|
|
276
|
+
admin: ["admin.mymodule.view", "admin.mymodule.edit", "admin.mymodule.delete"],
|
|
277
|
+
editor: ["admin.mymodule.view", "admin.mymodule.edit"],
|
|
278
|
+
viewer: ["admin.mymodule.view"],
|
|
279
|
+
noAccess: [],
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
const authClient = createInMemoryAuthClient({ users: mockUsers });
|
|
283
|
+
|
|
284
|
+
ReactDOM.createRoot(document.getElementById("root")!).render(
|
|
285
|
+
<React.StrictMode>
|
|
286
|
+
<AdminShell modules={[moduleManifest]} authClient={authClient}>
|
|
287
|
+
<App />
|
|
288
|
+
</AdminShell>
|
|
289
|
+
</React.StrictMode>
|
|
290
|
+
);
|
|
291
|
+
```
|
|
292
|
+
|
|
204
293
|
## Anti-Patterns (MUST NOT be present)
|
|
205
294
|
|
|
206
295
|
- [ ] No `@supabase/supabase-js` or `supabase` imports in `src/**`
|
package/README.md
CHANGED
|
@@ -539,7 +539,16 @@ Use [Lucide](https://lucide.dev/icons) icon names in **kebab-case**:
|
|
|
539
539
|
|
|
540
540
|
## Vite Configuration
|
|
541
541
|
|
|
542
|
-
The SDK provides
|
|
542
|
+
The SDK provides two ways to configure Vite for admin modules:
|
|
543
|
+
|
|
544
|
+
1. **`defineModuleConfig()`** — returns a complete Vite config. Best for new modules with no existing Vite setup.
|
|
545
|
+
2. **`adminModule()`** — returns a `Plugin[]` you spread into an existing config. Best for Lovable projects or any existing Vite config.
|
|
546
|
+
|
|
547
|
+
Both produce identical build artifacts. Both support `@vitejs/plugin-react` and `@vitejs/plugin-react-swc`.
|
|
548
|
+
|
|
549
|
+
> **Note:** `module.manifest.json` is generated automatically at build time by both `defineModuleConfig` and `adminModule`. No manual `cp admin.module.json dist/` step is needed.
|
|
550
|
+
|
|
551
|
+
### `defineModuleConfig()` — Full Config
|
|
543
552
|
|
|
544
553
|
```typescript
|
|
545
554
|
import { defineModuleConfig } from "@nsxbet/admin-sdk/vite";
|
|
@@ -547,7 +556,7 @@ import react from "@vitejs/plugin-react";
|
|
|
547
556
|
|
|
548
557
|
export default defineModuleConfig({
|
|
549
558
|
port: 3003,
|
|
550
|
-
plugins: [react()], // REQUIRED: you must add
|
|
559
|
+
plugins: [react()], // REQUIRED: you must add a React plugin
|
|
551
560
|
});
|
|
552
561
|
```
|
|
553
562
|
|
|
@@ -556,7 +565,7 @@ export default defineModuleConfig({
|
|
|
556
565
|
> - API: 4000
|
|
557
566
|
> - Modules: 3002, 3003, 3004, etc.
|
|
558
567
|
|
|
559
|
-
|
|
568
|
+
#### `defineModuleConfig` Options
|
|
560
569
|
|
|
561
570
|
| Option | Type | Default | Description |
|
|
562
571
|
|--------|------|---------|-------------|
|
|
@@ -567,6 +576,46 @@ export default defineModuleConfig({
|
|
|
567
576
|
| `additionalExternals` | string[] | `[]` | Extra externals |
|
|
568
577
|
| `overrides` | object | `{}` | Override any Vite config |
|
|
569
578
|
|
|
579
|
+
### `adminModule()` — Composable Plugin (Lovable / Custom Vite Config)
|
|
580
|
+
|
|
581
|
+
Use `adminModule()` when you already have a `vite.config.ts` and want to add admin module support without replacing it. This is the recommended approach for **Lovable projects**.
|
|
582
|
+
|
|
583
|
+
`adminModule()` only affects `vite build` — during `vite dev`, your app runs as a normal SPA with HMR working as expected.
|
|
584
|
+
|
|
585
|
+
```typescript
|
|
586
|
+
import { defineConfig } from "vite";
|
|
587
|
+
import react from "@vitejs/plugin-react-swc";
|
|
588
|
+
import path from "path";
|
|
589
|
+
import { componentTagger } from "lovable-tagger";
|
|
590
|
+
import { adminModule } from "@nsxbet/admin-sdk/vite";
|
|
591
|
+
|
|
592
|
+
export default defineConfig(({ mode }) => ({
|
|
593
|
+
server: {
|
|
594
|
+
host: "::",
|
|
595
|
+
port: 8080,
|
|
596
|
+
hmr: { overlay: false },
|
|
597
|
+
},
|
|
598
|
+
plugins: [
|
|
599
|
+
react(),
|
|
600
|
+
mode === "development" && componentTagger(),
|
|
601
|
+
...adminModule(),
|
|
602
|
+
].filter(Boolean),
|
|
603
|
+
resolve: {
|
|
604
|
+
alias: {
|
|
605
|
+
"@": path.resolve(__dirname, "./src"),
|
|
606
|
+
},
|
|
607
|
+
},
|
|
608
|
+
}));
|
|
609
|
+
```
|
|
610
|
+
|
|
611
|
+
#### `adminModule` Options
|
|
612
|
+
|
|
613
|
+
| Option | Type | Default | Description |
|
|
614
|
+
|--------|------|---------|-------------|
|
|
615
|
+
| `entry` | string | `"./src/spa.tsx"` | Entry file path |
|
|
616
|
+
| `outDir` | string | `"dist"` | Output directory |
|
|
617
|
+
| `additionalExternals` | string[] | `[]` | Extra externals |
|
|
618
|
+
|
|
570
619
|
### Shared Externals
|
|
571
620
|
|
|
572
621
|
These dependencies are provided by the shell (do not bundle them):
|
|
@@ -575,6 +624,65 @@ These dependencies are provided by the shell (do not bundle them):
|
|
|
575
624
|
["react", "react-dom", "react-router-dom", "i18next", "react-i18next"]
|
|
576
625
|
```
|
|
577
626
|
|
|
627
|
+
### Getting Started in Lovable
|
|
628
|
+
|
|
629
|
+
Lovable projects come with a default `vite.config.ts`, `index.html`, and `src/main.tsx` entry point. To turn a Lovable project into an admin module:
|
|
630
|
+
|
|
631
|
+
1. **Install the SDK:**
|
|
632
|
+
|
|
633
|
+
```bash
|
|
634
|
+
npm install @nsxbet/admin-sdk @nsxbet/admin-ui
|
|
635
|
+
```
|
|
636
|
+
|
|
637
|
+
2. **Add `adminModule()` to your existing `vite.config.ts`:**
|
|
638
|
+
|
|
639
|
+
```typescript
|
|
640
|
+
import { adminModule } from "@nsxbet/admin-sdk/vite";
|
|
641
|
+
|
|
642
|
+
// Inside your plugins array:
|
|
643
|
+
plugins: [
|
|
644
|
+
react(),
|
|
645
|
+
mode === "development" && componentTagger(),
|
|
646
|
+
...adminModule(),
|
|
647
|
+
].filter(Boolean),
|
|
648
|
+
```
|
|
649
|
+
|
|
650
|
+
3. **Create `admin.module.json`** at the project root with your module metadata.
|
|
651
|
+
|
|
652
|
+
4. **Create `src/spa.tsx`** — the shell entry point:
|
|
653
|
+
|
|
654
|
+
```tsx
|
|
655
|
+
import { App } from "./App";
|
|
656
|
+
export default App;
|
|
657
|
+
```
|
|
658
|
+
|
|
659
|
+
5. **Update `src/main.tsx`** — wrap your app with `AdminShell` for standalone dev:
|
|
660
|
+
|
|
661
|
+
```tsx
|
|
662
|
+
import { AdminShell, createInMemoryAuthClient, createMockUsersFromRoles } from "@nsxbet/admin-sdk";
|
|
663
|
+
import manifest from "../admin.module.json";
|
|
664
|
+
import { App } from "./App";
|
|
665
|
+
|
|
666
|
+
const mockUsers = createMockUsersFromRoles({
|
|
667
|
+
admin: ["admin.mymodule.view", "admin.mymodule.edit"],
|
|
668
|
+
editor: ["admin.mymodule.view", "admin.mymodule.edit"],
|
|
669
|
+
viewer: ["admin.mymodule.view"],
|
|
670
|
+
noAccess: [],
|
|
671
|
+
});
|
|
672
|
+
|
|
673
|
+
const authClient = createInMemoryAuthClient({ users: mockUsers });
|
|
674
|
+
|
|
675
|
+
ReactDOM.createRoot(document.getElementById("root")!).render(
|
|
676
|
+
<AdminShell modules={[manifest]} authClient={authClient}>
|
|
677
|
+
<App />
|
|
678
|
+
</AdminShell>
|
|
679
|
+
);
|
|
680
|
+
```
|
|
681
|
+
|
|
682
|
+
6. **Build:** `npm run build` produces `dist/assets/spa-[hash].js` + `dist/module.manifest.json`
|
|
683
|
+
|
|
684
|
+
Your Lovable preview (`vite dev`) continues to work as before — `adminModule()` only changes the `vite build` output.
|
|
685
|
+
|
|
578
686
|
## ESLint Plugin
|
|
579
687
|
|
|
580
688
|
Install `@nsxbet/eslint-plugin-admin` (requires ESLint 9+) to catch common mistakes at development time:
|
package/dist/vite/config.d.ts
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
+
import type { Plugin } from "vite";
|
|
1
2
|
/**
|
|
2
3
|
* Shared dependencies that are externalized in module builds.
|
|
3
4
|
* These are provided by the shell via import maps.
|
|
4
5
|
*/
|
|
5
6
|
export declare const SHARED_EXTERNALS: readonly ["react", "react-dom", "react-router-dom", "i18next", "react-i18next"];
|
|
6
|
-
export interface
|
|
7
|
-
/**
|
|
8
|
-
* Development server port
|
|
9
|
-
* @default 8080
|
|
10
|
-
*/
|
|
11
|
-
port?: number;
|
|
7
|
+
export interface AdminModuleOptions {
|
|
12
8
|
/**
|
|
13
9
|
* Entry file for the module SPA
|
|
14
10
|
* @default "./src/spa.tsx"
|
|
@@ -23,6 +19,13 @@ export interface ModuleConfigOptions {
|
|
|
23
19
|
* Additional externals to add to SHARED_EXTERNALS
|
|
24
20
|
*/
|
|
25
21
|
additionalExternals?: string[];
|
|
22
|
+
}
|
|
23
|
+
export interface ModuleConfigOptions extends AdminModuleOptions {
|
|
24
|
+
/**
|
|
25
|
+
* Development server port
|
|
26
|
+
* @default 8080
|
|
27
|
+
*/
|
|
28
|
+
port?: number;
|
|
26
29
|
/**
|
|
27
30
|
* Additional Vite plugins (will be spread into plugins array)
|
|
28
31
|
*/
|
|
@@ -32,17 +35,47 @@ export interface ModuleConfigOptions {
|
|
|
32
35
|
*/
|
|
33
36
|
overrides?: Record<string, any>;
|
|
34
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Composable Vite plugin array for admin modules.
|
|
40
|
+
* Returns plugins that handle build-time lib config, dist serving, and manifest generation.
|
|
41
|
+
*
|
|
42
|
+
* Use this when you already have a Vite config (e.g. Lovable) and want to add
|
|
43
|
+
* admin module support without replacing your entire config.
|
|
44
|
+
*
|
|
45
|
+
* The build config plugin only applies during `vite build` — dev server works as a normal SPA.
|
|
46
|
+
*
|
|
47
|
+
* @example In a Lovable project
|
|
48
|
+
* ```ts
|
|
49
|
+
* import { defineConfig } from "vite";
|
|
50
|
+
* import react from "@vitejs/plugin-react-swc";
|
|
51
|
+
* import { adminModule } from "@nsxbet/admin-sdk/vite";
|
|
52
|
+
*
|
|
53
|
+
* export default defineConfig(({ mode }) => ({
|
|
54
|
+
* plugins: [
|
|
55
|
+
* react(),
|
|
56
|
+
* mode === "development" && componentTagger(),
|
|
57
|
+
* ...adminModule(),
|
|
58
|
+
* ].filter(Boolean),
|
|
59
|
+
* }));
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @example With custom entry and externals
|
|
63
|
+
* ```ts
|
|
64
|
+
* ...adminModule({
|
|
65
|
+
* entry: "./src/custom-spa.tsx",
|
|
66
|
+
* additionalExternals: ["lodash"],
|
|
67
|
+
* })
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare function adminModule(options?: AdminModuleOptions): Plugin[];
|
|
35
71
|
/**
|
|
36
72
|
* Creates a pre-configured Vite config for admin modules.
|
|
37
73
|
*
|
|
38
74
|
* **Note:** This function does NOT include the React plugin automatically.
|
|
39
75
|
* You must import and add it yourself to avoid version conflicts.
|
|
40
76
|
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* - generateModuleManifestPlugin (generates module.manifest.json)
|
|
44
|
-
* - ES module build format
|
|
45
|
-
* - Externalized shared dependencies
|
|
77
|
+
* For Lovable or other existing Vite configs, use the composable `adminModule()` plugin
|
|
78
|
+
* instead — it can be spread into any existing plugins array.
|
|
46
79
|
*
|
|
47
80
|
* @example
|
|
48
81
|
* ```ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/vite/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/vite/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAGnC;;;GAGG;AACH,eAAO,MAAM,gBAAgB,iFAMnB,CAAC;AAEX,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;CAChC;AAED,MAAM,WAAW,mBAAoB,SAAQ,kBAAkB;IAC7D;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IAEH,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC;IAEhB;;OAEG;IAEH,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACjC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,WAAW,CAAC,OAAO,GAAE,kBAAuB,GAAG,MAAM,EAAE,CAwCtE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,GAAG,CAiBpE"}
|
package/dist/vite/config.js
CHANGED
|
@@ -10,17 +10,80 @@ export const SHARED_EXTERNALS = [
|
|
|
10
10
|
"i18next",
|
|
11
11
|
"react-i18next",
|
|
12
12
|
];
|
|
13
|
+
/**
|
|
14
|
+
* Composable Vite plugin array for admin modules.
|
|
15
|
+
* Returns plugins that handle build-time lib config, dist serving, and manifest generation.
|
|
16
|
+
*
|
|
17
|
+
* Use this when you already have a Vite config (e.g. Lovable) and want to add
|
|
18
|
+
* admin module support without replacing your entire config.
|
|
19
|
+
*
|
|
20
|
+
* The build config plugin only applies during `vite build` — dev server works as a normal SPA.
|
|
21
|
+
*
|
|
22
|
+
* @example In a Lovable project
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { defineConfig } from "vite";
|
|
25
|
+
* import react from "@vitejs/plugin-react-swc";
|
|
26
|
+
* import { adminModule } from "@nsxbet/admin-sdk/vite";
|
|
27
|
+
*
|
|
28
|
+
* export default defineConfig(({ mode }) => ({
|
|
29
|
+
* plugins: [
|
|
30
|
+
* react(),
|
|
31
|
+
* mode === "development" && componentTagger(),
|
|
32
|
+
* ...adminModule(),
|
|
33
|
+
* ].filter(Boolean),
|
|
34
|
+
* }));
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @example With custom entry and externals
|
|
38
|
+
* ```ts
|
|
39
|
+
* ...adminModule({
|
|
40
|
+
* entry: "./src/custom-spa.tsx",
|
|
41
|
+
* additionalExternals: ["lodash"],
|
|
42
|
+
* })
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export function adminModule(options = {}) {
|
|
46
|
+
const { entry = "./src/spa.tsx", outDir = "dist", additionalExternals = [], } = options;
|
|
47
|
+
const externals = [...SHARED_EXTERNALS, ...additionalExternals];
|
|
48
|
+
const buildConfigPlugin = {
|
|
49
|
+
name: "admin-module-build-config",
|
|
50
|
+
config(_config, { command }) {
|
|
51
|
+
if (command !== "build")
|
|
52
|
+
return;
|
|
53
|
+
return {
|
|
54
|
+
build: {
|
|
55
|
+
outDir,
|
|
56
|
+
emptyOutDir: true,
|
|
57
|
+
lib: {
|
|
58
|
+
entry,
|
|
59
|
+
formats: ["es"],
|
|
60
|
+
fileName: () => `assets/spa-[hash].js`,
|
|
61
|
+
},
|
|
62
|
+
rollupOptions: {
|
|
63
|
+
external: externals,
|
|
64
|
+
output: {
|
|
65
|
+
entryFileNames: "assets/[name]-[hash].js",
|
|
66
|
+
chunkFileNames: "assets/[name]-[hash].js",
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
return [
|
|
74
|
+
serveDistPlugin({ distDir: outDir }),
|
|
75
|
+
generateModuleManifestPlugin(),
|
|
76
|
+
buildConfigPlugin,
|
|
77
|
+
];
|
|
78
|
+
}
|
|
13
79
|
/**
|
|
14
80
|
* Creates a pre-configured Vite config for admin modules.
|
|
15
81
|
*
|
|
16
82
|
* **Note:** This function does NOT include the React plugin automatically.
|
|
17
83
|
* You must import and add it yourself to avoid version conflicts.
|
|
18
84
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* - generateModuleManifestPlugin (generates module.manifest.json)
|
|
22
|
-
* - ES module build format
|
|
23
|
-
* - Externalized shared dependencies
|
|
85
|
+
* For Lovable or other existing Vite configs, use the composable `adminModule()` plugin
|
|
86
|
+
* instead — it can be spread into any existing plugins array.
|
|
24
87
|
*
|
|
25
88
|
* @example
|
|
26
89
|
* ```ts
|
|
@@ -48,34 +111,13 @@ export const SHARED_EXTERNALS = [
|
|
|
48
111
|
*/
|
|
49
112
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
50
113
|
export function defineModuleConfig(options) {
|
|
51
|
-
const { port = 8080,
|
|
52
|
-
const externals = [...SHARED_EXTERNALS, ...additionalExternals];
|
|
114
|
+
const { port = 8080, plugins = [], overrides = {} } = options;
|
|
53
115
|
return {
|
|
54
|
-
plugins: [
|
|
55
|
-
serveDistPlugin({ distDir: outDir }),
|
|
56
|
-
generateModuleManifestPlugin(),
|
|
57
|
-
...plugins,
|
|
58
|
-
],
|
|
116
|
+
plugins: [...adminModule(options), ...plugins],
|
|
59
117
|
define: {
|
|
60
118
|
"process.env": {},
|
|
61
119
|
"process.env.NODE_ENV": JSON.stringify("production"),
|
|
62
120
|
},
|
|
63
|
-
build: {
|
|
64
|
-
outDir,
|
|
65
|
-
emptyOutDir: true,
|
|
66
|
-
lib: {
|
|
67
|
-
entry,
|
|
68
|
-
formats: ["es"],
|
|
69
|
-
fileName: () => `assets/spa-[hash].js`,
|
|
70
|
-
},
|
|
71
|
-
rollupOptions: {
|
|
72
|
-
external: externals,
|
|
73
|
-
output: {
|
|
74
|
-
entryFileNames: "assets/[name]-[hash].js",
|
|
75
|
-
chunkFileNames: "assets/[name]-[hash].js",
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
121
|
server: {
|
|
80
122
|
port,
|
|
81
123
|
},
|
package/dist/vite/index.d.ts
CHANGED
|
@@ -14,5 +14,5 @@
|
|
|
14
14
|
* @packageDocumentation
|
|
15
15
|
*/
|
|
16
16
|
export { generateModuleManifestPlugin, serveDistPlugin, type GenerateModuleManifestPluginOptions, type ServeDistPluginOptions, } from "./plugins.js";
|
|
17
|
-
export { defineModuleConfig, SHARED_EXTERNALS, type ModuleConfigOptions, } from "./config.js";
|
|
17
|
+
export { adminModule, defineModuleConfig, SHARED_EXTERNALS, type AdminModuleOptions, type ModuleConfigOptions, } from "./config.js";
|
|
18
18
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/vite/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vite/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACL,4BAA4B,EAC5B,eAAe,EACf,KAAK,mCAAmC,EACxC,KAAK,sBAAsB,GAC5B,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,KAAK,mBAAmB,GACzB,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vite/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACL,4BAA4B,EAC5B,eAAe,EACf,KAAK,mCAAmC,EACxC,KAAK,sBAAsB,GAC5B,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,gBAAgB,EAChB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,GACzB,MAAM,aAAa,CAAC"}
|
package/dist/vite/index.js
CHANGED
|
@@ -14,4 +14,4 @@
|
|
|
14
14
|
* @packageDocumentation
|
|
15
15
|
*/
|
|
16
16
|
export { generateModuleManifestPlugin, serveDistPlugin, } from "./plugins.js";
|
|
17
|
-
export { defineModuleConfig, SHARED_EXTERNALS, } from "./config.js";
|
|
17
|
+
export { adminModule, defineModuleConfig, SHARED_EXTERNALS, } from "./config.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nsxbet/admin-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "SDK for building NSX Admin modules with integrated shell",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"@nsxbet/admin-ui": "^0.2.0",
|
|
41
41
|
"@vitejs/plugin-react": "^4.0.0",
|
|
42
|
+
"@vitejs/plugin-react-swc": "^3.0.0",
|
|
42
43
|
"i18next": "^23.0.0 || ^24.0.0 || ^25.0.0",
|
|
43
44
|
"react": "^18.2.0",
|
|
44
45
|
"react-dom": "^18.2.0",
|
|
@@ -50,6 +51,9 @@
|
|
|
50
51
|
"@vitejs/plugin-react": {
|
|
51
52
|
"optional": true
|
|
52
53
|
},
|
|
54
|
+
"@vitejs/plugin-react-swc": {
|
|
55
|
+
"optional": true
|
|
56
|
+
},
|
|
53
57
|
"vite": {
|
|
54
58
|
"optional": true
|
|
55
59
|
}
|