@salesforce/vite-plugin-lwc-ui-bundle 1.131.2 → 1.132.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.
Files changed (32) hide show
  1. package/README.md +36 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +14 -4
  4. package/dist/index.js.map +1 -1
  5. package/dist/providers/index.d.ts +3 -1
  6. package/dist/providers/index.d.ts.map +1 -1
  7. package/dist/providers/index.js +4 -163
  8. package/dist/providers/index.js.map +1 -1
  9. package/dist/providers/lds/index.d.ts +10 -0
  10. package/dist/providers/lds/index.d.ts.map +1 -0
  11. package/dist/providers/lds/index.js +106 -0
  12. package/dist/providers/lds/index.js.map +1 -0
  13. package/dist/providers/lds/runtime.js +96 -0
  14. package/dist/providers/lds/runtime.js.map +1 -0
  15. package/dist/providers/lds/types.d.ts +22 -0
  16. package/dist/providers/lds/types.d.ts.map +1 -0
  17. package/dist/providers/lightning-graphql/index.d.ts +10 -0
  18. package/dist/providers/lightning-graphql/index.d.ts.map +1 -0
  19. package/dist/providers/lightning-graphql/index.js +24 -0
  20. package/dist/providers/lightning-graphql/index.js.map +1 -0
  21. package/dist/providers/lightning-graphql/runtime.js +103 -0
  22. package/dist/providers/lightning-graphql/runtime.js.map +1 -0
  23. package/dist/providers/shared/normalize-mcp-response.d.ts +20 -0
  24. package/dist/providers/shared/normalize-mcp-response.d.ts.map +1 -0
  25. package/dist/types.d.ts +1 -1
  26. package/dist/types.d.ts.map +1 -1
  27. package/docs/consumer-guide.md +429 -0
  28. package/package.json +21 -6
  29. package/skills/setup-lwc-vite-plugin/SKILL.md +242 -0
  30. package/dist/providers/lightning-graphql.d.ts +0 -17
  31. package/dist/providers/lightning-graphql.d.ts.map +0 -1
  32. package/docs/user-guide.md +0 -377
@@ -0,0 +1,429 @@
1
+ # Compiling LWC Components Off-Platform with @salesforce/vite-plugin-lwc-ui-bundle
2
+
3
+ This guide walks you through adding `@salesforce/vite-plugin-lwc-ui-bundle` to an
4
+ existing LWC project so you can compile your components into a single self-contained
5
+ `dist/index.html` that runs in any browser — no Salesforce org required.
6
+
7
+ ---
8
+
9
+ ## Prerequisites
10
+
11
+ - **Node.js** >= 20.0.0
12
+ - **LWC components** in a project directory (standard SFDX project or custom layout)
13
+ - **Salesforce CLI** (`sf`) — only needed if connecting to a real org (Tier 2)
14
+
15
+ ---
16
+
17
+ ## Overview
18
+
19
+ The plugin supports two tiers of usage:
20
+
21
+ | Tier | What You Get | Org Required? |
22
+ | ------------------------------- | ------------------------------------------ | ------------------ |
23
+ | **Tier 1: Off-Platform Build** | Static bundle with mock data, labels, i18n | No |
24
+ | **Tier 2: Live Org Connection** | Real GraphQL queries, live Salesforce data | Yes (via `sf` CLI) |
25
+
26
+ Start with Tier 1. Add Tier 2 later if your components use `lightning/graphql` or
27
+ need live data.
28
+
29
+ ---
30
+
31
+ ## Tier 1: Off-Platform Build
32
+
33
+ ### Project Structure
34
+
35
+ You need to add **3 files** to your project and update `package.json`:
36
+
37
+ ```
38
+ my-lwc-project/
39
+ ├── force-app/main/default/lwc/ ← your existing LWC components
40
+ │ ├── myApp/
41
+ │ │ ├── myApp.js
42
+ │ │ ├── myApp.html
43
+ │ │ └── myApp.js-meta.xml
44
+ │ └── myComponent/
45
+ │ ├── myComponent.js
46
+ │ ├── myComponent.html
47
+ │ └── myComponent.js-meta.xml
48
+ ├── bootstrap.js ← NEW: mounts your root component
49
+ ├── index.html ← NEW: entry point
50
+ ├── vite.config.js ← NEW: plugin configuration
51
+ └── package.json ← UPDATED: add deps and scripts
52
+ ```
53
+
54
+ ### Step 1: Install Dependencies
55
+
56
+ **Option A — Quick install command:**
57
+
58
+ ```bash
59
+ npm install @salesforce/vite-plugin-lwc-ui-bundle @lwc/rollup-plugin vite vite-plugin-singlefile --save-dev
60
+ npm install lwc @salesforce-ux/design-system lightning-base-components
61
+ ```
62
+
63
+ **Option B — Add to `package.json` manually, then `npm install`:**
64
+
65
+ ```json
66
+ {
67
+ "type": "module",
68
+ "scripts": {
69
+ "dev": "vite",
70
+ "build": "vite build",
71
+ "preview": "vite preview"
72
+ },
73
+ "dependencies": {
74
+ "@salesforce-ux/design-system": "^2.29.1",
75
+ "lightning-base-components": "^1.28.17-alpha",
76
+ "lwc": "^9.0.0"
77
+ },
78
+ "devDependencies": {
79
+ "@lwc/rollup-plugin": "^9.0.0",
80
+ "@salesforce/vite-plugin-lwc-ui-bundle": "^1.0.0",
81
+ "vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0",
82
+ "vite-plugin-singlefile": "^2.3.0"
83
+ }
84
+ }
85
+ ```
86
+
87
+ > **Important:** Add `"type": "module"` to your `package.json` if it is not already
88
+ > present. This is required for Vite's ESM-based config.
89
+
90
+ > **Note:** `@lwc/rollup-plugin` is a required peer dependency of the plugin.
91
+ > `lightning-base-components` is only needed if your components use `lightning/*`
92
+ > base components (e.g., `lightning-card`, `lightning-button`).
93
+
94
+ ### Step 2: Create `vite.config.js`
95
+
96
+ ```js
97
+ import { defineConfig } from "vite";
98
+ import lwcVitePlugin, { builtins } from "@salesforce/vite-plugin-lwc-ui-bundle";
99
+ import { viteSingleFile } from "vite-plugin-singlefile";
100
+
101
+ export default defineConfig({
102
+ build: {
103
+ target: "esnext",
104
+ minify: false,
105
+ },
106
+ plugins: [
107
+ lwcVitePlugin({
108
+ modules: {
109
+ // Flat SFDX structure: specify { path, namespace }
110
+ dirs: [{ path: "force-app/main/default/lwc", namespace: "c" }],
111
+
112
+ // Include if your components use lightning/* base components
113
+ npm: ["lightning-base-components"],
114
+ },
115
+ providers: [
116
+ builtins.label(),
117
+ builtins.i18n(),
118
+ builtins.client(),
119
+ builtins.gate(),
120
+ builtins.accessCheck(),
121
+ ],
122
+ }),
123
+ viteSingleFile(),
124
+ ],
125
+ });
126
+ ```
127
+
128
+ #### Component Directory Configuration
129
+
130
+ The plugin supports two directory structures:
131
+
132
+ **Flat SFDX structure** (standard Salesforce DX — most common):
133
+
134
+ ```
135
+ force-app/main/default/lwc/
136
+ myApp/
137
+ myApp.js
138
+ ```
139
+
140
+ Use `{ path, namespace }` to assign a namespace:
141
+
142
+ ```js
143
+ dirs: [{ path: "force-app/main/default/lwc", namespace: "c" }];
144
+ ```
145
+
146
+ Components are importable as `c/myApp` and rendered as `<c-my-app>`.
147
+
148
+ **Namespaced structure** (off-core projects):
149
+
150
+ ```
151
+ src/lwc/
152
+ myNamespace/
153
+ myComponent/
154
+ myComponent.js
155
+ ```
156
+
157
+ Omit `namespace` — the sub-directory name becomes the namespace:
158
+
159
+ ```js
160
+ dirs: ["src/lwc"];
161
+ ```
162
+
163
+ Components are importable as `myNamespace/myComponent`.
164
+
165
+ #### Configuring Labels
166
+
167
+ The `builtins.label()` provider handles `@salesforce/label/*` imports. How you
168
+ configure it depends on your project:
169
+
170
+ **SFDX project with `CustomLabels.labels-meta.xml`:**
171
+
172
+ Copy label values from your XML into the label provider config:
173
+
174
+ ```js
175
+ builtins.label({
176
+ "c.appTitle": "My LWC App",
177
+ "c.saveButton": "Save",
178
+ "c.cancelButton": "Cancel",
179
+ }),
180
+ ```
181
+
182
+ **Off-core project (no labels XML):**
183
+
184
+ Pass label key-value pairs directly. If no override is provided for a key, the
185
+ plugin returns a human-readable fallback derived from the key name (e.g.,
186
+ `c.appTitle` renders as "App Title").
187
+
188
+ ```js
189
+ // Minimal — uses fallback display for all labels
190
+ builtins.label(),
191
+
192
+ // With explicit overrides
193
+ builtins.label({
194
+ "c.appTitle": "My App Title",
195
+ "c.greeting": "Welcome!",
196
+ }),
197
+ ```
198
+
199
+ #### Why `gate()` and `accessCheck()` Are Needed
200
+
201
+ Even if your components don't use `@salesforce/gate/*` or `@salesforce/accessCheck/*`
202
+ directly, **`lightning-base-components` does internally**. Without these providers,
203
+ you'll get runtime errors like:
204
+
205
+ ```
206
+ Uncaught TypeError: Cannot read properties of undefined (reading 'isOpen')
207
+ ```
208
+
209
+ Always include `builtins.gate()` and `builtins.accessCheck()` when using
210
+ `lightning-base-components`.
211
+
212
+ ### Step 3: Create `index.html`
213
+
214
+ ```html
215
+ <!doctype html>
216
+ <html lang="en">
217
+ <head>
218
+ <meta charset="UTF-8" />
219
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
220
+ <title>My LWC App</title>
221
+ </head>
222
+ <body>
223
+ <div id="app"></div>
224
+ <script>
225
+ globalThis.lwcRuntimeFlags = { DISABLE_SYNTHETIC_SHADOW: true };
226
+ </script>
227
+ <script type="module" src="/bootstrap.js"></script>
228
+ </body>
229
+ </html>
230
+ ```
231
+
232
+ ### Step 4: Create `bootstrap.js`
233
+
234
+ ```js
235
+ import "@salesforce-ux/design-system/assets/styles/salesforce-lightning-design-system.css";
236
+ import "@lwc/synthetic-shadow";
237
+ import { createElement } from "lwc";
238
+
239
+ // Import your root component using its LWC specifier: <namespace>/<componentName>
240
+ import App from "c/myApp";
241
+
242
+ // Mount it — tag name is the kebab-case version of the specifier
243
+ const el = createElement("c-my-app", { is: App });
244
+ document.getElementById("app").appendChild(el);
245
+ ```
246
+
247
+ Replace `c/myApp` and `c-my-app` with your actual root component name.
248
+
249
+ ### Step 5: Build and Test
250
+
251
+ ```bash
252
+ # Production build — outputs dist/index.html (single-file bundle)
253
+ npm run build
254
+
255
+ # Open directly in browser
256
+ open dist/index.html
257
+
258
+ # Or use dev server with live reload
259
+ npm run dev
260
+ # Open http://localhost:5173
261
+
262
+ # Or preview the production build
263
+ npm run preview
264
+ # Open http://localhost:4173
265
+ ```
266
+
267
+ ---
268
+
269
+ ## Tier 2: Live Org Connection (lwcProxy)
270
+
271
+ If your components use `lightning/graphql` or need live Salesforce data, add
272
+ `lwcProxy()` to connect to a real org during development.
273
+
274
+ ### Prerequisites
275
+
276
+ - Salesforce CLI installed and an org connected: `sf org display`
277
+ - Additional packages: `@salesforce/sdk-data` and `@salesforce/ui-bundle`
278
+
279
+ ### Step 1: Install Additional Dependencies
280
+
281
+ ```bash
282
+ npm install @salesforce/sdk-data @salesforce/ui-bundle
283
+ ```
284
+
285
+ ### Step 2: Update `vite.config.js`
286
+
287
+ Add `lwcProxy()` before `lwcVitePlugin()` and add `builtins.lightningGraphql()`
288
+ to providers:
289
+
290
+ ```js
291
+ import { defineConfig } from "vite";
292
+ import lwcVitePlugin, { builtins, lwcProxy } from "@salesforce/vite-plugin-lwc-ui-bundle";
293
+ import { viteSingleFile } from "vite-plugin-singlefile";
294
+
295
+ export default defineConfig({
296
+ build: {
297
+ target: "esnext",
298
+ minify: false,
299
+ },
300
+ plugins: [
301
+ lwcProxy({ debug: true }),
302
+ // lwcProxy({ orgAlias: "my-org", debug: true }), // explicit org
303
+ lwcVitePlugin({
304
+ modules: {
305
+ dirs: [{ path: "force-app/main/default/lwc", namespace: "c" }],
306
+ npm: ["lightning-base-components"],
307
+ },
308
+ providers: [
309
+ builtins.label(),
310
+ builtins.i18n(),
311
+ builtins.client(),
312
+ builtins.gate(),
313
+ builtins.accessCheck(),
314
+ builtins.lightningGraphql(),
315
+ ],
316
+ }),
317
+ viteSingleFile(),
318
+ ],
319
+ });
320
+ ```
321
+
322
+ ### Step 3: Update `bootstrap.js`
323
+
324
+ Initialize the Data SDK before mounting your app. This requires top-level `await`
325
+ (hence `target: "esnext"` in the vite config):
326
+
327
+ ```js
328
+ import "@salesforce-ux/design-system/assets/styles/salesforce-lightning-design-system.css";
329
+ import "@lwc/synthetic-shadow";
330
+ import { createElement } from "lwc";
331
+
332
+ // Initialize SDK — lwcProxy() handles /services/* in the Vite dev server
333
+ import { createDataSDK } from "@salesforce/sdk-data";
334
+ try {
335
+ globalThis.__sfdc_sdk__ = await createDataSDK({ uiBundle: { basePath: "/" } });
336
+ } catch (_err) {
337
+ globalThis.__sfdc_sdk__ = {};
338
+ }
339
+
340
+ // Import your root component
341
+ import App from "c/myApp";
342
+
343
+ const el = createElement("c-my-app", { is: App });
344
+ document.getElementById("app").appendChild(el);
345
+ ```
346
+
347
+ ### Step 4: Run Dev Server
348
+
349
+ ```bash
350
+ npm run dev
351
+ # Terminal shows: [lwc-proxy] Connected to https://your-org.my.salesforce.com
352
+ # Open http://localhost:5173
353
+ ```
354
+
355
+ Components using `@wire(graphql, ...)` will now execute real GraphQL queries
356
+ against your connected org. The proxy intercepts `/services/*` calls inside
357
+ the Vite dev server — no separate proxy process needed.
358
+
359
+ > **Note:** `lwcProxy()` works with `npm run dev` only. The production build
360
+ > (`dist/index.html`) does not include the proxy — it's a static file. For
361
+ > production use with live data, you need a separate API proxy or MCP server.
362
+
363
+ ---
364
+
365
+ ## Common Errors
366
+
367
+ ### `Cannot read properties of undefined (reading 'isOpen')`
368
+
369
+ Missing `gate()` provider. `lightning-base-components` use gates internally.
370
+ Add `builtins.gate()` to your providers array.
371
+
372
+ ### `Rollup failed to resolve import "lightning/button"`
373
+
374
+ Your component uses a Lightning Base Component. Add to `vite.config.js`:
375
+
376
+ ```js
377
+ modules: {
378
+ npm: ["lightning-base-components"],
379
+ }
380
+ ```
381
+
382
+ ### `Top-level await is not available in the configured target environment`
383
+
384
+ Your `bootstrap.js` uses top-level `await` (required for Data SDK). Add
385
+ `target: "esnext"` to the build config:
386
+
387
+ ```js
388
+ build: { target: "esnext" },
389
+ ```
390
+
391
+ ### `[scoped-module-providers] Unhandled import: @salesforce/label/...`
392
+
393
+ Expected — the plugin returns the label key as display text by default.
394
+ To provide specific label values:
395
+
396
+ ```js
397
+ builtins.label({ "c.Save": "Save", "c.Cancel": "Cancel" }),
398
+ ```
399
+
400
+ ### `Rollup failed to resolve import "force/someModule"`
401
+
402
+ Core-only module not available off-platform. Add a stub:
403
+
404
+ ```js
405
+ // stubs/someModule.js
406
+ export const someExport = () => {};
407
+ ```
408
+
409
+ ```js
410
+ // vite.config.js
411
+ lwcVitePlugin({ stubs: { "force/someModule": "./stubs/someModule.js" } });
412
+ ```
413
+
414
+ ### Component renders but looks unstyled
415
+
416
+ Add SLDS import to `bootstrap.js`:
417
+
418
+ ```js
419
+ import "@salesforce-ux/design-system/assets/styles/salesforce-lightning-design-system.css";
420
+ ```
421
+
422
+ ---
423
+
424
+ ## Reference
425
+
426
+ - **npm:** https://www.npmjs.com/package/@salesforce/vite-plugin-lwc-ui-bundle
427
+ - **Source:** https://github.com/salesforce-experience-platform-emu/webapps/tree/main/packages/vite-plugin-lwc-ui-bundle
428
+ - **User Guide:** https://github.com/salesforce-experience-platform-emu/webapps/blob/main/packages/vite-plugin-lwc-ui-bundle/docs/user-guide.md
429
+ - **Example project:** https://git.soma.salesforce.com/sisi-zhang/my-lwc-app-test
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/vite-plugin-lwc-ui-bundle",
3
- "version": "1.131.2",
3
+ "version": "1.132.0",
4
4
  "description": "Vite plugin for compiling LWC components into static bundles for off-platform and MCP use",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "author": "Salesforce",
@@ -30,6 +30,14 @@
30
30
  "types": "./dist/providers/index.d.ts",
31
31
  "import": "./dist/providers/index.js"
32
32
  },
33
+ "./providers/lds": {
34
+ "types": "./dist/providers/lds/index.d.ts",
35
+ "import": "./dist/providers/lds/index.js"
36
+ },
37
+ "./providers/lightning-graphql": {
38
+ "types": "./dist/providers/lightning-graphql/index.d.ts",
39
+ "import": "./dist/providers/lightning-graphql/index.js"
40
+ },
33
41
  "./package.json": "./package.json"
34
42
  },
35
43
  "main": "./dist/index.js",
@@ -37,10 +45,11 @@
37
45
  "files": [
38
46
  "dist",
39
47
  "README.md",
40
- "docs"
48
+ "docs",
49
+ "skills"
41
50
  ],
42
51
  "scripts": {
43
- "build": "vite build",
52
+ "build": "vite build && vite build --mode runtime-lds && vite build --mode runtime-lightning-graphql",
44
53
  "clean": "rm -rf dist",
45
54
  "dev": "vite build --watch",
46
55
  "test": "vitest run",
@@ -51,19 +60,25 @@
51
60
  "@lwc/rollup-plugin": "^9.0.0",
52
61
  "@salesforce/sdk-chat": "^1.123.0",
53
62
  "@salesforce/ui-bundle": "^1.123.0",
54
- "vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
63
+ "vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0",
64
+ "zod": "^3.23.8"
55
65
  },
56
66
  "peerDependenciesMeta": {
57
67
  "@salesforce/ui-bundle": {
58
68
  "optional": true
59
69
  }
60
70
  },
71
+ "dependencies": {
72
+ "es-module-lexer": "^1.7.0",
73
+ "magic-string": "^0.30.17"
74
+ },
61
75
  "devDependencies": {
62
- "@salesforce/sdk-chat": "^1.131.2",
76
+ "@salesforce/sdk-chat": "^1.132.0",
63
77
  "typescript": "^5.9.3",
64
78
  "vite": "^7.0.0",
65
79
  "vite-plugin-dts": "^4.5.4",
66
- "vitest": "^4.0.6"
80
+ "vitest": "^4.0.6",
81
+ "zod": "^3.23.8"
67
82
  },
68
83
  "engines": {
69
84
  "node": ">=20.0.0"