@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.
- package/README.md +36 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -4
- package/dist/index.js.map +1 -1
- package/dist/providers/index.d.ts +3 -1
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +4 -163
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/lds/index.d.ts +10 -0
- package/dist/providers/lds/index.d.ts.map +1 -0
- package/dist/providers/lds/index.js +106 -0
- package/dist/providers/lds/index.js.map +1 -0
- package/dist/providers/lds/runtime.js +96 -0
- package/dist/providers/lds/runtime.js.map +1 -0
- package/dist/providers/lds/types.d.ts +22 -0
- package/dist/providers/lds/types.d.ts.map +1 -0
- package/dist/providers/lightning-graphql/index.d.ts +10 -0
- package/dist/providers/lightning-graphql/index.d.ts.map +1 -0
- package/dist/providers/lightning-graphql/index.js +24 -0
- package/dist/providers/lightning-graphql/index.js.map +1 -0
- package/dist/providers/lightning-graphql/runtime.js +103 -0
- package/dist/providers/lightning-graphql/runtime.js.map +1 -0
- package/dist/providers/shared/normalize-mcp-response.d.ts +20 -0
- package/dist/providers/shared/normalize-mcp-response.d.ts.map +1 -0
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/docs/consumer-guide.md +429 -0
- package/package.json +21 -6
- package/skills/setup-lwc-vite-plugin/SKILL.md +242 -0
- package/dist/providers/lightning-graphql.d.ts +0 -17
- package/dist/providers/lightning-graphql.d.ts.map +0 -1
- package/docs/user-guide.md +0 -377
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: setup-lwc-vite-plugin
|
|
3
|
+
description: >
|
|
4
|
+
Set up @salesforce/vite-plugin-lwc-ui-bundle in an LWC project so components
|
|
5
|
+
compile and run off-platform in a browser. Use this skill whenever someone wants
|
|
6
|
+
to: run LWC components outside Salesforce, build a static LWC bundle, add Vite
|
|
7
|
+
to an SFDX or LWC project, compile LWC for a browser, create a standalone LWC
|
|
8
|
+
app, set up an LWC dev server, or use vite-plugin-lwc-ui-bundle. Also use it
|
|
9
|
+
when the user mentions "off-platform LWC", "LWC bundle", "LWC without Salesforce",
|
|
10
|
+
"LWC without an org", "Vite + LWC", or "compile LWC off-core".
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# Setup @salesforce/vite-plugin-lwc-ui-bundle
|
|
14
|
+
|
|
15
|
+
This skill adds `@salesforce/vite-plugin-lwc-ui-bundle` to an existing LWC project,
|
|
16
|
+
producing a single `dist/index.html` that runs in any browser without a Salesforce org.
|
|
17
|
+
|
|
18
|
+
## What the plugin does
|
|
19
|
+
|
|
20
|
+
It wraps the full LWC compilation pipeline behind a single Vite plugin: scoped module
|
|
21
|
+
providers (labels, i18n, gates, etc.), Lightning npm resolution, missing CSS handling,
|
|
22
|
+
and the Vite/LWC bridge. The output is a self-contained HTML file with all JS and CSS
|
|
23
|
+
inlined.
|
|
24
|
+
|
|
25
|
+
## Reference material
|
|
26
|
+
|
|
27
|
+
The `references/consumer-guide.md` file contains exact file templates, dependency
|
|
28
|
+
versions, and config snippets. Read it when you need to generate `vite.config.js`,
|
|
29
|
+
`index.html`, `bootstrap.js`, or `package.json` updates. This skill tells you
|
|
30
|
+
_when and why_ to use each piece; the consumer guide gives you the exact _what_.
|
|
31
|
+
|
|
32
|
+
## Interactive Setup Flow
|
|
33
|
+
|
|
34
|
+
Walk the user through these steps in order. Ask questions — don't assume.
|
|
35
|
+
|
|
36
|
+
### Step 1: Detect the project
|
|
37
|
+
|
|
38
|
+
LWC projects come in two layouts, and the directory structure determines how
|
|
39
|
+
`modules.dirs` must be configured. Detecting the layout first avoids misconfigured
|
|
40
|
+
imports that silently fail at build time.
|
|
41
|
+
|
|
42
|
+
Check in order:
|
|
43
|
+
|
|
44
|
+
1. `sfdx-project.json` in the project root → **SFDX project**. Components live at
|
|
45
|
+
`force-app/main/default/lwc/` in a flat structure where every component shares
|
|
46
|
+
the `c` namespace. Configure as `dirs: [{ path: "force-app/main/default/lwc", namespace: "c" }]`.
|
|
47
|
+
2. Directories matching `src/lwc/` or `modules/` → **off-core project**. Sub-directories
|
|
48
|
+
are namespaces (e.g., `src/lwc/myNs/myComponent/`). Configure as `dirs: ["src/lwc"]`.
|
|
49
|
+
3. If neither found, ask the user where their LWC components live.
|
|
50
|
+
|
|
51
|
+
Read `package.json` to understand what's already installed — avoid adding duplicate
|
|
52
|
+
dependencies later.
|
|
53
|
+
|
|
54
|
+
### Step 2: Ask for the root component
|
|
55
|
+
|
|
56
|
+
The plugin compiles a tree starting from one root component that gets mounted in the
|
|
57
|
+
HTML page. The user needs to tell you which one, since there's no reliable way to
|
|
58
|
+
auto-detect the "main" component.
|
|
59
|
+
|
|
60
|
+
List the discovered components and ask:
|
|
61
|
+
|
|
62
|
+
> "Which component should be the root of your app? This is the one that gets
|
|
63
|
+
> mounted in the HTML page."
|
|
64
|
+
|
|
65
|
+
Present the component names as a numbered list for easy selection.
|
|
66
|
+
|
|
67
|
+
### Step 3: Inspect the component tree
|
|
68
|
+
|
|
69
|
+
This step drives every downstream decision: which providers to include, whether
|
|
70
|
+
`lightning-base-components` is needed, and whether to offer Tier 2 (live org). Getting
|
|
71
|
+
this right prevents cryptic build errors.
|
|
72
|
+
|
|
73
|
+
Starting from the root component, trace the dependency tree:
|
|
74
|
+
|
|
75
|
+
1. Read the root component's `.html` file — find all `c-*` tags (or other
|
|
76
|
+
namespace tags) to identify child components
|
|
77
|
+
2. Recursively read each child component's `.js` and `.html`
|
|
78
|
+
3. Collect all imports across the tree:
|
|
79
|
+
- `@salesforce/label/*` → label keys (need `builtins.label()`)
|
|
80
|
+
- `lightning/graphql` or `@wire(graphql` → needs GraphQL support
|
|
81
|
+
- `lightning/*` base components → needs `lightning-base-components` npm package,
|
|
82
|
+
plus `gate()`, `accessCheck()`, and `primitiveUtils()` providers because
|
|
83
|
+
base components use these modules internally even if user code doesn't
|
|
84
|
+
- `@salesforce/gate/*`, `@salesforce/accessCheck/*` → handled by providers
|
|
85
|
+
- `@salesforce/i18n/*` → i18n provider
|
|
86
|
+
- `@salesforce/client/*` → client provider (provides `formFactor` based on viewport width)
|
|
87
|
+
- `lightning/primitiveUtils` → primitiveUtils provider
|
|
88
|
+
|
|
89
|
+
Report what you found:
|
|
90
|
+
|
|
91
|
+
> "I traced your component tree from `c/app`. Here's what I found:
|
|
92
|
+
>
|
|
93
|
+
> - 5 components total
|
|
94
|
+
> - 3 label imports: `c.appTitle`, `c.greeting`, `c.save`
|
|
95
|
+
> - Uses `lightning-card` (needs lightning-base-components)
|
|
96
|
+
> - Uses `lightning/graphql` (needs lwcProxy for live data)
|
|
97
|
+
> - No gate/accessCheck imports in your code, but lightning-base-components
|
|
98
|
+
> uses them internally — I'll include those providers automatically."
|
|
99
|
+
|
|
100
|
+
### Step 4: Decide the tier
|
|
101
|
+
|
|
102
|
+
The plugin supports two tiers. This determines which dependencies and bootstrap
|
|
103
|
+
code to generate.
|
|
104
|
+
|
|
105
|
+
| Tier | What you get | Org required? |
|
|
106
|
+
| ------------------------------- | ------------------------------------------ | ------------------ |
|
|
107
|
+
| **Tier 1: Off-Platform Build** | Static bundle with mock data, labels, i18n | No |
|
|
108
|
+
| **Tier 2: Live Org Connection** | Real GraphQL queries via `lwcProxy()` | Yes (via `sf` CLI) |
|
|
109
|
+
|
|
110
|
+
If GraphQL usage was detected in Step 3, ask:
|
|
111
|
+
|
|
112
|
+
> "Your components use `lightning/graphql`. Do you want to connect to a real
|
|
113
|
+
> Salesforce org for live data during development?
|
|
114
|
+
>
|
|
115
|
+
> A) Yes — I have an org connected via `sf` CLI (adds lwcProxy + Data SDK)
|
|
116
|
+
> B) No — use mock data for now (GraphQL wire adapter returns empty results)"
|
|
117
|
+
|
|
118
|
+
If no GraphQL detected, default to Tier 1 — there's no benefit to Tier 2 without
|
|
119
|
+
GraphQL or live data needs.
|
|
120
|
+
|
|
121
|
+
### Step 5: Resolve label values
|
|
122
|
+
|
|
123
|
+
Labels need explicit values because the plugin can't read them from an org at build
|
|
124
|
+
time. Getting them right here means the user sees realistic text immediately instead
|
|
125
|
+
of placeholder keys.
|
|
126
|
+
|
|
127
|
+
1. **SFDX project**: Check for `force-app/main/default/labels/CustomLabels.labels-meta.xml`.
|
|
128
|
+
If found, parse it and extract `<fullName>` → `<value>` pairs for the label
|
|
129
|
+
keys discovered in Step 3.
|
|
130
|
+
2. **Off-core project or no labels XML**: For each label key found, use a
|
|
131
|
+
placeholder value derived from the key (e.g., `c.appTitle` → `"App Title"`).
|
|
132
|
+
|
|
133
|
+
Tell the user what labels you found and the values you'll use:
|
|
134
|
+
|
|
135
|
+
> "I found 3 label imports. Here are the values I'll configure:
|
|
136
|
+
>
|
|
137
|
+
> - `c.appTitle` → "My LWC App" (from CustomLabels.labels-meta.xml)
|
|
138
|
+
> - `c.greeting` → "Welcome!" (from CustomLabels.labels-meta.xml)
|
|
139
|
+
> - `c.save` → "Save" (fallback — not found in labels XML)
|
|
140
|
+
>
|
|
141
|
+
> You can change these in `vite.config.js` later."
|
|
142
|
+
|
|
143
|
+
If no labels were found at all, still include `builtins.label()` with no overrides.
|
|
144
|
+
The plugin returns a human-readable fallback for unknown keys, and
|
|
145
|
+
`lightning-base-components` may use labels internally.
|
|
146
|
+
|
|
147
|
+
### Step 6: Generate files
|
|
148
|
+
|
|
149
|
+
Read `references/consumer-guide.md` for the exact file templates. Generate these
|
|
150
|
+
files, adapting the templates based on what you learned in Steps 1-5:
|
|
151
|
+
|
|
152
|
+
#### Files to create or update
|
|
153
|
+
|
|
154
|
+
1. **`package.json`** — merge in dependencies and scripts (don't overwrite existing).
|
|
155
|
+
See "Step 1: Install Dependencies" in the consumer guide for the full dep list.
|
|
156
|
+
- Add `"type": "module"` if not present
|
|
157
|
+
- Only add `lightning-base-components` and `@salesforce-ux/design-system` if
|
|
158
|
+
the component tree uses `lightning/*` base components
|
|
159
|
+
- For Tier 2, also add `@salesforce/sdk-data` and `@salesforce/ui-bundle`
|
|
160
|
+
|
|
161
|
+
2. **`vite.config.js`** — see "Step 2" in the consumer guide for the template.
|
|
162
|
+
Adapt based on your findings:
|
|
163
|
+
- Set `dirs` for the detected project structure (SFDX vs namespaced)
|
|
164
|
+
- Populate `builtins.label({...})` with values from Step 5
|
|
165
|
+
- Include `builtins.primitiveUtils()` if using `lightning-base-components`
|
|
166
|
+
- Include `builtins.lightningGraphql()` only if GraphQL was detected
|
|
167
|
+
- Remove `npm: ["lightning-base-components"]` if no base components used
|
|
168
|
+
- For Tier 2, add `lwcProxy()` before `lwcVitePlugin()` in the plugins array
|
|
169
|
+
|
|
170
|
+
3. **`index.html`** — see "Step 3" in the consumer guide.
|
|
171
|
+
|
|
172
|
+
4. **`bootstrap.js`** (project root) — see "Step 4" (Tier 1) or "Step 3" (Tier 2)
|
|
173
|
+
in the consumer guide. Replace the component name with the actual root from
|
|
174
|
+
Step 2. Remove the SLDS CSS import if `lightning-base-components` is not used.
|
|
175
|
+
|
|
176
|
+
#### Advanced options (use only when needed)
|
|
177
|
+
|
|
178
|
+
The plugin accepts additional options for complex projects. Only add these if the
|
|
179
|
+
component tree inspection reveals a need:
|
|
180
|
+
|
|
181
|
+
- **`stubs`**: Map bare module specifiers to stub files for core-only modules
|
|
182
|
+
not available off-platform (e.g., `{ "force/someModule": "./stubs/someModule.js" }`).
|
|
183
|
+
Needed when components import platform modules like `aura`, `logger`, or
|
|
184
|
+
`force/*` that don't exist outside Salesforce.
|
|
185
|
+
- **`lwcOptions`**: Pass-through options for `@lwc/rollup-plugin` to configure
|
|
186
|
+
LWC compiler behavior (e.g., `{ enableDynamicComponents: true }`). Only needed
|
|
187
|
+
for projects using advanced LWC features like dynamic component creation.
|
|
188
|
+
- **`passthroughRules`**: Let specific imports bypass the provider system. Each
|
|
189
|
+
rule has a `specifierPrefix` and `importerPattern` — when both match, the import
|
|
190
|
+
resolves normally. Useful when an npm package (like `lightning-base-components`)
|
|
191
|
+
has its own label definitions that shouldn't be intercepted by your label provider.
|
|
192
|
+
- **`ignorePatterns`**: Specifier prefixes that providers should never intercept.
|
|
193
|
+
Defaults include `@salesforce/sdk-*` and `@salesforce/core`. Extend this if
|
|
194
|
+
you have imports that look like provider-handled patterns but should resolve
|
|
195
|
+
through normal Node module resolution.
|
|
196
|
+
|
|
197
|
+
### Step 7: Install and build
|
|
198
|
+
|
|
199
|
+
Run:
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
npm install
|
|
203
|
+
npm run build
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
If the build succeeds, report the output file size and open it:
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
open dist/index.html
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
If the build fails, diagnose and fix. See the "Common Errors" section in
|
|
213
|
+
`references/consumer-guide.md` for the full troubleshooting guide. The most
|
|
214
|
+
frequent issues:
|
|
215
|
+
|
|
216
|
+
- **`Cannot read properties of undefined (reading 'isOpen')`**: Missing `gate()`
|
|
217
|
+
or `accessCheck()` provider — `lightning-base-components` use gates internally.
|
|
218
|
+
- **`Rollup failed to resolve import "lightning/button"`**: Missing
|
|
219
|
+
`npm: ["lightning-base-components"]` in modules config.
|
|
220
|
+
- **`Unhandled import: @salesforce/label/...`**: Expected warning — the plugin
|
|
221
|
+
returns the key as display text. Add overrides to `builtins.label()` to customize.
|
|
222
|
+
- **`Top-level await is not available`**: Missing `target: "esnext"` in build config.
|
|
223
|
+
- **`Rollup failed to resolve import "force/someModule"`**: Core-only module. Add
|
|
224
|
+
a stub via the `stubs` option.
|
|
225
|
+
- **Component renders but looks unstyled**: Missing SLDS CSS import in bootstrap.js.
|
|
226
|
+
|
|
227
|
+
### Step 8: Test dev server (Tier 2 only)
|
|
228
|
+
|
|
229
|
+
If lwcProxy was configured:
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
npm run dev
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Confirm the terminal shows `[lwc-proxy] Connected to https://...`. Open
|
|
236
|
+
`http://localhost:5173` and verify GraphQL queries return real data.
|
|
237
|
+
|
|
238
|
+
## Reference
|
|
239
|
+
|
|
240
|
+
- npm: https://www.npmjs.com/package/@salesforce/vite-plugin-lwc-ui-bundle
|
|
241
|
+
- README: https://github.com/salesforce-experience-platform-emu/webapps/tree/main/packages/vite-plugin-lwc-ui-bundle
|
|
242
|
+
- Consumer Guide: https://github.com/salesforce-experience-platform-emu/webapps/blob/main/packages/vite-plugin-lwc-ui-bundle/docs/consumer-guide.md
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Provider } from '../types';
|
|
2
|
-
export interface LightningGraphqlOptions {
|
|
3
|
-
/**
|
|
4
|
-
* Name of the MCP tool to call for GraphQL query execution.
|
|
5
|
-
* Defaults to `'graphqlQuery'`.
|
|
6
|
-
*
|
|
7
|
-
* The tool must accept `{ query: string; variables?: Record<string, unknown> }`
|
|
8
|
-
* and return a GraphQL-shaped response: `{ data: unknown; errors?: unknown[] }`.
|
|
9
|
-
*
|
|
10
|
-
* The result is normalised across surfaces:
|
|
11
|
-
* - OpenAI surface: `sdk.callTool()` resolves with `{ result: "<JSON string>" }`
|
|
12
|
-
* - MCP Apps surface: `sdk.callTool()` resolves with `{ structuredContent, content }`
|
|
13
|
-
*/
|
|
14
|
-
toolName?: string;
|
|
15
|
-
}
|
|
16
|
-
export declare function lightningGraphql(options?: LightningGraphqlOptions): Provider;
|
|
17
|
-
//# sourceMappingURL=lightning-graphql.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lightning-graphql.d.ts","sourceRoot":"","sources":["../../src/providers/lightning-graphql.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,WAAW,uBAAuB;IACvC;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AA0KD,wBAAgB,gBAAgB,CAAC,OAAO,GAAE,uBAA4B,GAAG,QAAQ,CAShF"}
|
package/docs/user-guide.md
DELETED
|
@@ -1,377 +0,0 @@
|
|
|
1
|
-
# User Guide: Compiling LWC Components into a Static Bundle
|
|
2
|
-
|
|
3
|
-
This guide walks through using `@salesforce/vite-plugin-lwc-ui-bundle` to compile
|
|
4
|
-
your existing LWC components into a single self-contained `dist/index.html` —
|
|
5
|
-
no server required, opens directly in a browser.
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## Prerequisites
|
|
10
|
-
|
|
11
|
-
- Node.js >= 20.0.0
|
|
12
|
-
- Your LWC components already exist in a Salesforce DX project
|
|
13
|
-
|
|
14
|
-
---
|
|
15
|
-
|
|
16
|
-
## Project Structure
|
|
17
|
-
|
|
18
|
-
The example project `my-lwc-app` uses the standard Salesforce DX flat structure:
|
|
19
|
-
|
|
20
|
-
```
|
|
21
|
-
my-lwc-app/
|
|
22
|
-
├── force-app/main/default/lwc/
|
|
23
|
-
│ ├── helloApp/ ← component directly, no namespace folder
|
|
24
|
-
│ │ ├── helloApp.js
|
|
25
|
-
│ │ ├── helloApp.html
|
|
26
|
-
│ │ └── helloApp.js-meta.xml
|
|
27
|
-
│ └── helloMessage/
|
|
28
|
-
│ ├── helloMessage.js
|
|
29
|
-
│ ├── helloMessage.html
|
|
30
|
-
│ └── helloMessage.js-meta.xml
|
|
31
|
-
├── src/
|
|
32
|
-
│ └── bootstrap.js ← mounts root component
|
|
33
|
-
├── index.html ← entry point
|
|
34
|
-
├── vite.config.js ← plugin config
|
|
35
|
-
└── package.json
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
Use `namespace: 'c'` in `vite.config.js` to tell the plugin to treat this flat
|
|
39
|
-
structure as namespace `c` — components are then importable as `'c/helloApp'`.
|
|
40
|
-
|
|
41
|
-
---
|
|
42
|
-
|
|
43
|
-
## Step 1: Add Files
|
|
44
|
-
|
|
45
|
-
### `package.json`
|
|
46
|
-
|
|
47
|
-
```json
|
|
48
|
-
{
|
|
49
|
-
"name": "my-lwc-app",
|
|
50
|
-
"version": "1.0.0",
|
|
51
|
-
"type": "module",
|
|
52
|
-
"scripts": {
|
|
53
|
-
"build": "vite build",
|
|
54
|
-
"dev": "vite",
|
|
55
|
-
"preview": "vite preview"
|
|
56
|
-
},
|
|
57
|
-
"devDependencies": {
|
|
58
|
-
"@lwc/rollup-plugin": "^9.0.0",
|
|
59
|
-
"@salesforce/vite-plugin-lwc-ui-bundle": "^1.0.0",
|
|
60
|
-
"vite": "^7.0.0",
|
|
61
|
-
"vite-plugin-singlefile": "^2.3.0"
|
|
62
|
-
},
|
|
63
|
-
"dependencies": {
|
|
64
|
-
"@salesforce-ux/design-system": "^2.29.1",
|
|
65
|
-
"lightning-base-components": "^1.28.17-alpha",
|
|
66
|
-
"lwc": "^9.0.0"
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
### `vite.config.js`
|
|
72
|
-
|
|
73
|
-
```js
|
|
74
|
-
import { defineConfig } from "vite";
|
|
75
|
-
import lwcVitePlugin from "@salesforce/vite-plugin-lwc-ui-bundle";
|
|
76
|
-
import { viteSingleFile } from "vite-plugin-singlefile";
|
|
77
|
-
|
|
78
|
-
export default defineConfig({
|
|
79
|
-
build: {
|
|
80
|
-
target: "esnext", // required for top-level await in bootstrap.js
|
|
81
|
-
},
|
|
82
|
-
plugins: [
|
|
83
|
-
lwcVitePlugin({
|
|
84
|
-
modules: {
|
|
85
|
-
// Flat DX structure: specify { path, namespace } per directory
|
|
86
|
-
// Use a plain string if your dir already has namespace sub-folders
|
|
87
|
-
dirs: [{ path: "force-app/main/default/lwc", namespace: "c" }],
|
|
88
|
-
|
|
89
|
-
// Include if your components use lightning/* base components
|
|
90
|
-
npm: ["lightning-base-components"],
|
|
91
|
-
},
|
|
92
|
-
}),
|
|
93
|
-
viteSingleFile(), // inlines everything into a single index.html
|
|
94
|
-
],
|
|
95
|
-
});
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
### `index.html`
|
|
99
|
-
|
|
100
|
-
```html
|
|
101
|
-
<!doctype html>
|
|
102
|
-
<html lang="en">
|
|
103
|
-
<head>
|
|
104
|
-
<meta charset="UTF-8" />
|
|
105
|
-
<title>My LWC App</title>
|
|
106
|
-
</head>
|
|
107
|
-
<body>
|
|
108
|
-
<div id="app"></div>
|
|
109
|
-
<script>
|
|
110
|
-
globalThis.lwcRuntimeFlags = { DISABLE_SYNTHETIC_SHADOW: true };
|
|
111
|
-
</script>
|
|
112
|
-
<script type="module" src="/src/bootstrap.js"></script>
|
|
113
|
-
</body>
|
|
114
|
-
</html>
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
### `src/bootstrap.js`
|
|
118
|
-
|
|
119
|
-
```js
|
|
120
|
-
import "@salesforce-ux/design-system/assets/styles/salesforce-lightning-design-system.css";
|
|
121
|
-
import "@lwc/synthetic-shadow";
|
|
122
|
-
import { createElement } from "lwc";
|
|
123
|
-
|
|
124
|
-
// Import your root component using its LWC specifier: <namespace>/<componentName>
|
|
125
|
-
import App from "c/helloApp";
|
|
126
|
-
|
|
127
|
-
// Mount it — tag name is the kebab-case version of the specifier
|
|
128
|
-
const el = createElement("c-hello-app", { is: App });
|
|
129
|
-
document.getElementById("app").appendChild(el);
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
---
|
|
133
|
-
|
|
134
|
-
## Step 2: Install Dependencies
|
|
135
|
-
|
|
136
|
-
```bash
|
|
137
|
-
npm install
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
---
|
|
141
|
-
|
|
142
|
-
## Step 3: Build
|
|
143
|
-
|
|
144
|
-
```bash
|
|
145
|
-
npm run build
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
Output: `dist/index.html` — a single file with all JS and CSS inlined.
|
|
149
|
-
|
|
150
|
-
---
|
|
151
|
-
|
|
152
|
-
## Step 4: Test
|
|
153
|
-
|
|
154
|
-
**Option A — Open directly in browser:**
|
|
155
|
-
|
|
156
|
-
```bash
|
|
157
|
-
open dist/index.html
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
**Option B — Dev server with live reload:**
|
|
161
|
-
|
|
162
|
-
```bash
|
|
163
|
-
npm run dev
|
|
164
|
-
# Open http://localhost:5173
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
**Option C — Preview the production build:**
|
|
168
|
-
|
|
169
|
-
```bash
|
|
170
|
-
npm run preview
|
|
171
|
-
# Open http://localhost:4173
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
---
|
|
175
|
-
|
|
176
|
-
## Component Namespace Convention
|
|
177
|
-
|
|
178
|
-
The plugin supports two directory structures:
|
|
179
|
-
|
|
180
|
-
### Flat DX structure (standard Salesforce DX)
|
|
181
|
-
|
|
182
|
-
```
|
|
183
|
-
force-app/main/default/lwc/
|
|
184
|
-
helloApp/
|
|
185
|
-
helloApp.js
|
|
186
|
-
```
|
|
187
|
-
|
|
188
|
-
Use `{ path, namespace }` per directory to specify the namespace:
|
|
189
|
-
|
|
190
|
-
```js
|
|
191
|
-
modules: {
|
|
192
|
-
dirs: [{ path: "force-app/main/default/lwc", namespace: "c" }];
|
|
193
|
-
}
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
| Directory | LWC Specifier | HTML Tag |
|
|
197
|
-
| ------------------- | ------------------ | ----------------- |
|
|
198
|
-
| `lwc/helloApp/` | `'c/helloApp'` | `c-hello-app` |
|
|
199
|
-
| `lwc/helloMessage/` | `'c/helloMessage'` | `c-hello-message` |
|
|
200
|
-
|
|
201
|
-
### Namespaced structure
|
|
202
|
-
|
|
203
|
-
```
|
|
204
|
-
modules/
|
|
205
|
-
records/
|
|
206
|
-
accountOutputName/
|
|
207
|
-
accountOutputName.js
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
Omit `namespace` — the sub-directory name is used as the namespace:
|
|
211
|
-
|
|
212
|
-
```js
|
|
213
|
-
modules: {
|
|
214
|
-
dirs: ["modules"];
|
|
215
|
-
}
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
| Directory | LWC Specifier | HTML Tag |
|
|
219
|
-
| ------------------------------------ | ----------------------------- | ----------------------------- |
|
|
220
|
-
| `modules/records/accountOutputName/` | `'records/accountOutputName'` | `records-account-output-name` |
|
|
221
|
-
|
|
222
|
-
---
|
|
223
|
-
|
|
224
|
-
## Common Errors
|
|
225
|
-
|
|
226
|
-
### `Rollup failed to resolve import "lightning/button"`
|
|
227
|
-
|
|
228
|
-
Your component uses a Lightning Base Component. Add to `vite.config.js`:
|
|
229
|
-
|
|
230
|
-
```js
|
|
231
|
-
modules: {
|
|
232
|
-
npm: ["lightning-base-components"];
|
|
233
|
-
}
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
### `[scoped-module-providers] Unhandled import: @salesforce/label/...`
|
|
237
|
-
|
|
238
|
-
Expected — the plugin returns the label key as display text by default.
|
|
239
|
-
To provide real label values:
|
|
240
|
-
|
|
241
|
-
```js
|
|
242
|
-
import { builtins } from "@salesforce/vite-plugin-lwc-ui-bundle";
|
|
243
|
-
|
|
244
|
-
lwcVitePlugin({
|
|
245
|
-
providers: [builtins.label({ "c.Save": "Save", "c.Cancel": "Cancel" })],
|
|
246
|
-
});
|
|
247
|
-
```
|
|
248
|
-
|
|
249
|
-
### Component renders but looks unstyled
|
|
250
|
-
|
|
251
|
-
Add SLDS import to `src/bootstrap.js`:
|
|
252
|
-
|
|
253
|
-
```js
|
|
254
|
-
import "@salesforce-ux/design-system/assets/styles/salesforce-lightning-design-system.css";
|
|
255
|
-
```
|
|
256
|
-
|
|
257
|
-
### `[scoped-module-providers] Unhandled import: @salesforce/user/Id`
|
|
258
|
-
|
|
259
|
-
Expected warning — `@salesforce/user/*` imports return `undefined` by default.
|
|
260
|
-
To provide real values (e.g. current user ID), add the user provider:
|
|
261
|
-
|
|
262
|
-
```js
|
|
263
|
-
import { builtins } from "@salesforce/vite-plugin-lwc-ui-bundle";
|
|
264
|
-
|
|
265
|
-
lwcVitePlugin({
|
|
266
|
-
providers: [
|
|
267
|
-
builtins.user({ Id: "005xx000001X8AAAA" }), // optional: override user fields
|
|
268
|
-
],
|
|
269
|
-
});
|
|
270
|
-
```
|
|
271
|
-
|
|
272
|
-
### `Top-level await is not available in the configured target environment`
|
|
273
|
-
|
|
274
|
-
Your `bootstrap.js` uses top-level `await` (required when initialising the Data
|
|
275
|
-
SDK). Add `target: 'esnext'` to the build config:
|
|
276
|
-
|
|
277
|
-
```js
|
|
278
|
-
export default defineConfig({
|
|
279
|
-
build: { target: "esnext" },
|
|
280
|
-
plugins: [...],
|
|
281
|
-
});
|
|
282
|
-
```
|
|
283
|
-
|
|
284
|
-
### `Rollup failed to resolve import "force/someModule"`
|
|
285
|
-
|
|
286
|
-
Core-only module — add a stub:
|
|
287
|
-
|
|
288
|
-
```js
|
|
289
|
-
// stubs/someModule.js
|
|
290
|
-
export const someExport = () => {};
|
|
291
|
-
```
|
|
292
|
-
|
|
293
|
-
```js
|
|
294
|
-
// vite.config.js
|
|
295
|
-
lwcVitePlugin({ stubs: { "force/someModule": "./stubs/someModule.js" } });
|
|
296
|
-
```
|
|
297
|
-
|
|
298
|
-
---
|
|
299
|
-
|
|
300
|
-
## Connecting to a Real Salesforce Org (lwcProxy)
|
|
301
|
-
|
|
302
|
-
By default the plugin runs fully off-platform with mock data. To connect your
|
|
303
|
-
components to a real Salesforce org in local dev — enabling `lightning/graphql`
|
|
304
|
-
to execute real queries — add `lwcProxy()` alongside `lwcVitePlugin()`.
|
|
305
|
-
|
|
306
|
-
### Prerequisites
|
|
307
|
-
|
|
308
|
-
- Salesforce CLI installed and an org connected: `sf org display`
|
|
309
|
-
- Additional packages: `@salesforce/sdk-data` and `@salesforce/ui-bundle`
|
|
310
|
-
|
|
311
|
-
```bash
|
|
312
|
-
npm install @salesforce/sdk-data @salesforce/ui-bundle
|
|
313
|
-
```
|
|
314
|
-
|
|
315
|
-
### 1. Add lwcProxy to vite.config.js
|
|
316
|
-
|
|
317
|
-
```js
|
|
318
|
-
import { defineConfig } from "vite";
|
|
319
|
-
import lwcVitePlugin, { lwcProxy } from "@salesforce/vite-plugin-lwc-ui-bundle";
|
|
320
|
-
import { viteSingleFile } from "vite-plugin-singlefile";
|
|
321
|
-
|
|
322
|
-
export default defineConfig({
|
|
323
|
-
build: {
|
|
324
|
-
target: "esnext", // required for top-level await in bootstrap.js
|
|
325
|
-
},
|
|
326
|
-
plugins: [
|
|
327
|
-
lwcProxy(), // auto-reads sf CLI default org credentials
|
|
328
|
-
// lwcProxy({ orgAlias: "my-org", debug: true }) // explicit org + verbose logging
|
|
329
|
-
lwcVitePlugin({
|
|
330
|
-
modules: {
|
|
331
|
-
dirs: [{ path: "force-app/main/default/lwc", namespace: "c" }],
|
|
332
|
-
},
|
|
333
|
-
}),
|
|
334
|
-
viteSingleFile(),
|
|
335
|
-
],
|
|
336
|
-
});
|
|
337
|
-
```
|
|
338
|
-
|
|
339
|
-
### 2. Initialise the Data SDK in bootstrap.js
|
|
340
|
-
|
|
341
|
-
The SDK must be initialised before any component that uses `lightning/graphql`
|
|
342
|
-
mounts. Use a top-level `await` import to guarantee ordering:
|
|
343
|
-
|
|
344
|
-
```js
|
|
345
|
-
import "@salesforce-ux/design-system/assets/styles/salesforce-lightning-design-system.css";
|
|
346
|
-
import "@lwc/synthetic-shadow";
|
|
347
|
-
import { createElement } from "lwc";
|
|
348
|
-
|
|
349
|
-
// Initialise the Data SDK — lwcProxy() handles /services/* on the Vite dev server
|
|
350
|
-
import { createDataSDK } from "@salesforce/sdk-data";
|
|
351
|
-
try {
|
|
352
|
-
globalThis.__sfdc_sdk__ = await createDataSDK({
|
|
353
|
-
uiBundle: { basePath: "/" },
|
|
354
|
-
});
|
|
355
|
-
} catch (_err) {
|
|
356
|
-
globalThis.__sfdc_sdk__ = {};
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
import App from "c/helloApp";
|
|
360
|
-
const el = createElement("c-hello-app", { is: App });
|
|
361
|
-
document.getElementById("app").appendChild(el);
|
|
362
|
-
```
|
|
363
|
-
|
|
364
|
-
### 3. Run the dev server
|
|
365
|
-
|
|
366
|
-
```bash
|
|
367
|
-
npm run dev
|
|
368
|
-
# Terminal shows: [lwc-proxy] Connected to https://your-org.my.salesforce.com
|
|
369
|
-
# Open http://localhost:5173
|
|
370
|
-
```
|
|
371
|
-
|
|
372
|
-
Components using `lightning/graphql` will now execute real GraphQL queries
|
|
373
|
-
against your org. The proxy intercepts `/services/*` calls inside the Vite dev
|
|
374
|
-
server — no separate proxy process needed.
|
|
375
|
-
|
|
376
|
-
> **Note:** The `basePath: '/'` setting works for `npm run dev` only. For
|
|
377
|
-
> production builds (`dist/index.html`), a standalone proxy server is required.
|