@salesforce/vite-plugin-lwc-ui-bundle 1.130.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 (43) hide show
  1. package/LICENSE.txt +82 -0
  2. package/README.md +222 -0
  3. package/dist/discovery.d.ts +3 -0
  4. package/dist/discovery.d.ts.map +1 -0
  5. package/dist/index.d.ts +10 -0
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +509 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/plugins/lightning-npm.d.ts +4 -0
  10. package/dist/plugins/lightning-npm.d.ts.map +1 -0
  11. package/dist/plugins/lwc-bridge.d.ts +3 -0
  12. package/dist/plugins/lwc-bridge.d.ts.map +1 -0
  13. package/dist/plugins/lwc-wrapper.d.ts +6 -0
  14. package/dist/plugins/lwc-wrapper.d.ts.map +1 -0
  15. package/dist/plugins/missing-css.d.ts +3 -0
  16. package/dist/plugins/missing-css.d.ts.map +1 -0
  17. package/dist/plugins/proxy.d.ts +26 -0
  18. package/dist/plugins/proxy.d.ts.map +1 -0
  19. package/dist/plugins/scoped-providers.d.ts +4 -0
  20. package/dist/plugins/scoped-providers.d.ts.map +1 -0
  21. package/dist/providers/access-check.d.ts +3 -0
  22. package/dist/providers/access-check.d.ts.map +1 -0
  23. package/dist/providers/client.d.ts +3 -0
  24. package/dist/providers/client.d.ts.map +1 -0
  25. package/dist/providers/gate.d.ts +3 -0
  26. package/dist/providers/gate.d.ts.map +1 -0
  27. package/dist/providers/i18n.d.ts +7 -0
  28. package/dist/providers/i18n.d.ts.map +1 -0
  29. package/dist/providers/index.d.ts +13 -0
  30. package/dist/providers/index.d.ts.map +1 -0
  31. package/dist/providers/index.js +462 -0
  32. package/dist/providers/index.js.map +1 -0
  33. package/dist/providers/label.d.ts +3 -0
  34. package/dist/providers/label.d.ts.map +1 -0
  35. package/dist/providers/lightning-graphql.d.ts +17 -0
  36. package/dist/providers/lightning-graphql.d.ts.map +1 -0
  37. package/dist/providers/primitive-utils.d.ts +3 -0
  38. package/dist/providers/primitive-utils.d.ts.map +1 -0
  39. package/dist/types.d.ts +44 -0
  40. package/dist/types.d.ts.map +1 -0
  41. package/docs/chat-wrapper-guide.md +134 -0
  42. package/docs/user-guide.md +377 -0
  43. package/package.json +74 -0
package/LICENSE.txt ADDED
@@ -0,0 +1,82 @@
1
+ Terms of Use
2
+
3
+ Copyright 2026 Salesforce, Inc. All rights reserved.
4
+
5
+ These Terms of Use govern the download, installation, and/or use of this
6
+ software provided by Salesforce, Inc. ("Salesforce") (the "Software"), were
7
+ last updated on April 15, 2025, and constitute a legally binding
8
+ agreement between you and Salesforce. If you do not agree to these Terms of
9
+ Use, do not install or use the Software.
10
+
11
+ Salesforce grants you a worldwide, non-exclusive, no-charge, royalty-free
12
+ copyright license to reproduce, prepare derivative works of, publicly
13
+ display, publicly perform, sublicense, and distribute the Software and
14
+ derivative works subject to these Terms. These Terms shall be included in
15
+ all copies or substantial portions of the Software.
16
+
17
+ Subject to the limited rights expressly granted hereunder, Salesforce
18
+ reserves all rights, title, and interest in and to all intellectual
19
+ property subsisting in the Software. No rights are granted to you hereunder
20
+ other than as expressly set forth herein. Users residing in countries on
21
+ the United States Office of Foreign Assets Control sanction list, or which
22
+ are otherwise subject to a US export embargo, may not use the Software.
23
+
24
+ Implementation of the Software may require development work, for which you
25
+ are responsible. The Software may contain bugs, errors and
26
+ incompatibilities and is made available on an AS IS basis without support,
27
+ updates, or service level commitments.
28
+
29
+ Salesforce reserves the right at any time to modify, suspend, or
30
+ discontinue, the Software (or any part thereof) with or without notice. You
31
+ agree that Salesforce shall not be liable to you or to any third party for
32
+ any modification, suspension, or discontinuance.
33
+
34
+ You agree to defend Salesforce against any claim, demand, suit or
35
+ proceeding made or brought against Salesforce by a third party arising out
36
+ of or accruing from (a) your use of the Software, and (b) any application
37
+ you develop with the Software that infringes any copyright, trademark,
38
+ trade secret, trade dress, patent, or other intellectual property right of
39
+ any person or defames any person or violates their rights of publicity or
40
+ privacy (each a "Claim Against Salesforce"), and will indemnify Salesforce
41
+ from any damages, attorney fees, and costs finally awarded against
42
+ Salesforce as a result of, or for any amounts paid by Salesforce under a
43
+ settlement approved by you in writing of, a Claim Against Salesforce,
44
+ provided Salesforce (x) promptly gives you written notice of the Claim
45
+ Against Salesforce, (y) gives you sole control of the defense and
46
+ settlement of the Claim Against Salesforce (except that you may not settle
47
+ any Claim Against Salesforce unless it unconditionally releases Salesforce
48
+ of all liability), and (z) gives you all reasonable assistance, at your
49
+ expense.
50
+
51
+ WITHOUT LIMITING THE GENERALITY OF THE FOREGOING, THE SOFTWARE IS NOT
52
+ SUPPORTED AND IS PROVIDED "AS IS," WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
53
+ IMPLIED. IN NO EVENT SHALL SALESFORCE HAVE ANY LIABILITY FOR ANY DAMAGES,
54
+ INCLUDING, BUT NOT LIMITED TO, DIRECT, INDIRECT, SPECIAL, INCIDENTAL,
55
+ PUNITIVE, OR CONSEQUENTIAL DAMAGES, OR DAMAGES BASED ON LOST PROFITS, DATA,
56
+ OR USE, IN CONNECTION WITH THE SOFTWARE, HOWEVER CAUSED AND WHETHER IN
57
+ CONTRACT, TORT, OR UNDER ANY OTHER THEORY OF LIABILITY, WHETHER OR NOT YOU
58
+ HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
59
+
60
+ These Terms of Use shall be governed exclusively by the internal laws of
61
+ the State of California, without regard to its conflicts of laws
62
+ rules. Each party hereby consents to the exclusive jurisdiction of the
63
+ state and federal courts located in San Francisco County, California to
64
+ adjudicate any dispute arising out of or relating to these Terms of Use and
65
+ the download, installation, and/or use of the Software. Except as expressly
66
+ stated herein, these Terms of Use constitute the entire agreement between
67
+ the parties, and supersede all prior and contemporaneous agreements,
68
+ proposals, or representations, written or oral, concerning their subject
69
+ matter. No modification, amendment, or waiver of any provision of these
70
+ Terms of Use shall be effective unless it is by an update to these Terms of
71
+ Use that Salesforce makes available, or is in writing and signed by the
72
+ party against whom the modification, amendment, or waiver is to be
73
+ asserted.
74
+
75
+ Data Privacy: Salesforce may collect, process, and store device,
76
+ system, and other information related to your use of the Software. This
77
+ information includes, but is not limited to, IP address, user metrics, and
78
+ other data ("Usage Data"). Salesforce may use Usage Data for analytics,
79
+ product development, and marketing purposes. You acknowledge that files
80
+ generated in conjunction with the Software may contain sensitive or
81
+ confidential data, and you are solely responsible for anonymizing and
82
+ protecting such data.
package/README.md ADDED
@@ -0,0 +1,222 @@
1
+ # @salesforce/vite-plugin-lwc-ui-bundle
2
+
3
+ Vite plugin for compiling and running LWC components off-platform. Bundles the full compilation pipeline — scoped module providers, Lightning npm resolution, missing CSS handling, and the Vite/LWC bridge — behind a single configurable entry point.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @salesforce/vite-plugin-lwc-ui-bundle @lwc/rollup-plugin --save-dev
9
+ ```
10
+
11
+ `@lwc/rollup-plugin` is a required peer dependency.
12
+
13
+ ## Quick Start
14
+
15
+ ```js
16
+ // vite.config.js
17
+ import { defineConfig } from "vite";
18
+ import lwcVitePlugin, { builtins } from "@salesforce/vite-plugin-lwc-ui-bundle";
19
+
20
+ export default defineConfig({
21
+ plugins: [
22
+ lwcVitePlugin({
23
+ modules: {
24
+ dirs: ["sf/lwc"],
25
+ npm: ["lwc-components-lightning"],
26
+ },
27
+ providers: [
28
+ builtins.label(),
29
+ builtins.i18n(),
30
+ builtins.accessCheck(),
31
+ builtins.client(),
32
+ builtins.gate(),
33
+ builtins.primitiveUtils(),
34
+ ],
35
+ }),
36
+ ],
37
+ });
38
+ ```
39
+
40
+ ## Configuration
41
+
42
+ ### `modules`
43
+
44
+ Controls where LWC component sources are discovered.
45
+
46
+ | Property | Type | Description |
47
+ | -------- | ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
48
+ | `dirs` | `string[]` | Directories to scan for `{namespace}/{component}/{component}.js` entries. Each subdirectory of a dir is treated as a namespace. |
49
+ | `npm` | `(string \| {npm: string})[]` | NPM packages that supply LWC modules. Passed through to `@lwc/rollup-plugin`. |
50
+
51
+ ```js
52
+ modules: {
53
+ dirs: ['sf/lwc', 'src/components'],
54
+ npm: ['lwc-components-lightning'],
55
+ }
56
+ ```
57
+
58
+ ### `providers`
59
+
60
+ Ordered array of scoped module providers. Each provider intercepts imports matching its prefix and returns generated JavaScript source. Providers are evaluated in order; the first to return a non-null result wins.
61
+
62
+ ```js
63
+ providers: [
64
+ builtins.label({ "Custom.MyLabel": "Hello World" }),
65
+ builtins.i18n(),
66
+ builtins.gate({ myFeature: false }),
67
+ builtins.accessCheck(),
68
+ builtins.client(),
69
+ builtins.primitiveUtils(),
70
+ ];
71
+ ```
72
+
73
+ ### `stubs`
74
+
75
+ Map of bare module specifiers to stub file paths. These are injected as Vite `resolve.alias` entries.
76
+
77
+ ```js
78
+ stubs: {
79
+ aura: 'src/stubs/aura-off-platform.js',
80
+ logger: 'src/stubs/logger-stub.js',
81
+ }
82
+ ```
83
+
84
+ ### `lwcOptions`
85
+
86
+ Pass-through options for `@lwc/rollup-plugin`. See the [@lwc/rollup-plugin docs](https://github.com/nicknisi/lwc/tree/master/packages/%40lwc/rollup-plugin) for available options.
87
+
88
+ ```js
89
+ lwcOptions: {
90
+ enableDynamicComponents: true,
91
+ enableSyntheticElementInternals: true,
92
+ }
93
+ ```
94
+
95
+ ### `ignorePatterns`
96
+
97
+ Specifier prefixes that should never be intercepted by providers, even if they match a provider or intercept prefix. Defaults to `['@salesforce/sdk-', '@salesforce/core']`.
98
+
99
+ ### `passthroughRules`
100
+
101
+ Rules for selectively letting specific imports resolve normally. Each rule has a `specifierPrefix` and `importerPattern`; when an import matches both, it bypasses the provider system.
102
+
103
+ ```js
104
+ passthroughRules: [
105
+ {
106
+ specifierPrefix: "@salesforce/label/",
107
+ importerPattern: "/lwc-components-lightning/",
108
+ },
109
+ ];
110
+ ```
111
+
112
+ ## Built-in Providers
113
+
114
+ All built-in providers are factory functions exported from `vite-plugin-lwc-ui-bundle` as `builtins.*` (or individually from `@salesforce/vite-plugin-lwc-ui-bundle/providers`).
115
+
116
+ ### `label(overrides?)`
117
+
118
+ Handles `@salesforce/label/*`. Returns label strings from a defaults map; unknown labels get a camelCase-to-words fallback. Pass `overrides` to add or replace defaults.
119
+
120
+ ### `i18n(options?)`
121
+
122
+ Handles `@salesforce/i18n/*`. Browser-derived values (lang, locale, currency, etc.) use the Intl API at runtime. Format patterns use en-US defaults. Accepts `staticOverrides` and `objectOverrides`.
123
+
124
+ ### `gate(overrides?)`
125
+
126
+ Handles `@salesforce/gate/*`. All gates default to open. Pass a map of gate names to `false` to close specific gates.
127
+
128
+ ### `accessCheck(overrides?)`
129
+
130
+ Handles `@salesforce/accessCheck/*`. All checks default to `false`. Pass overrides to change individual checks.
131
+
132
+ ### `client()`
133
+
134
+ Handles `@salesforce/client/*`. Supports `formFactor` (Small/Medium/Large via CSS media queries at runtime).
135
+
136
+ ### `primitiveUtils()`
137
+
138
+ Handles `lightning/primitiveUtils`. Stubs `normalizeBoolean` and `reflectAttribute`.
139
+
140
+ ## Custom Providers
141
+
142
+ Create custom providers by implementing the provider interface:
143
+
144
+ ```js
145
+ function myProvider() {
146
+ return {
147
+ // prefix: imports starting with this string will be routed to this provider.
148
+ // The parent @scope/ prefix is auto-derived and used as a catch-all intercept.
149
+ prefix: "@myorg/config/",
150
+
151
+ // resolve: given a full import specifier, return JavaScript source or null to pass.
152
+ resolve(specifier) {
153
+ if (!specifier.startsWith("@myorg/config/")) return null;
154
+ const key = specifier.slice("@myorg/config/".length);
155
+ return `export default ${JSON.stringify(myConfigMap[key])};`;
156
+ },
157
+ };
158
+ }
159
+ ```
160
+
161
+ For providers that don't use a prefix-based match (like `lightning/primitiveUtils`), add a `match` function:
162
+
163
+ ```js
164
+ {
165
+ match(id) { return id === 'lightning/primitiveUtils'; },
166
+ resolve(specifier) { /* ... */ },
167
+ }
168
+ ```
169
+
170
+ ## Internal Plugins
171
+
172
+ The plugin factory returns an array of coordinated Vite plugins:
173
+
174
+ | Plugin | Purpose |
175
+ | ------------------------------------- | ---------------------------------------------------- |
176
+ | `vite-plugin-scoped-module-providers` | Virtual module orchestrator for providers |
177
+ | `vite-plugin-resolve-lightning-npm` | Resolves `lightning/*` from npm with local overrides |
178
+ | `vite-plugin-lwc-missing-css` | Empty CSS for HTML-only templates |
179
+ | `vite-plugin-lwc-bridge` | Bridges Vite/LWC HTML and CSS conflicts |
180
+ | `rollup-plugin-lwc-compiler` | `@lwc/rollup-plugin` with Vite guard rails |
181
+ | `vite-plugin-lwc-stubs` | Alias stubs (only present if `stubs` is non-empty) |
182
+
183
+ ## Local Salesforce Dev (lwcProxy)
184
+
185
+ `lwcProxy()` is an optional companion plugin that proxies Salesforce API calls to a connected org, enabling `lightning/graphql` to work in local dev without an MCP server.
186
+
187
+ ### Setup
188
+
189
+ ```bash
190
+ npm install @salesforce/vite-plugin-lwc-ui-bundle @salesforce/sdk-data @salesforce/ui-bundle
191
+ ```
192
+
193
+ ```js
194
+ // vite.config.js
195
+ import lwcVitePlugin, { lwcProxy } from '@salesforce/vite-plugin-lwc-ui-bundle';
196
+
197
+ export default defineConfig({
198
+ plugins: [
199
+ lwcProxy(), // reads sf CLI default org; pass { orgAlias: 'myOrg' } to specify
200
+ lwcVitePlugin({ ... }),
201
+ ],
202
+ });
203
+ ```
204
+
205
+ ```js
206
+ // src/bootstrap.js — initialise before the app mounts
207
+ import { createDataSDK } from "@salesforce/sdk-data";
208
+ globalThis.__sfdc_sdk__ = await createDataSDK({ uiBundle: { basePath: "/" } });
209
+ ```
210
+
211
+ ### How it works
212
+
213
+ - `lwcProxy()` intercepts `/services/*` and `/lwr/*` requests in the Vite dev server and forwards them to Salesforce with the org's access token
214
+ - Credentials are read automatically from the `sf` CLI (uses `@salesforce/ui-bundle/app`, an optional peer dep)
215
+ - `lightning/graphql` checks `globalThis.__sfdc_sdk__` first; if not set, falls back to the MCP surface (`getChatSDK().callTool`)
216
+
217
+ ### Options
218
+
219
+ | Option | Type | Default | Description |
220
+ | ---------- | --------- | ------------------ | ------------------------------------ |
221
+ | `orgAlias` | `string` | sf CLI default org | Salesforce org alias |
222
+ | `debug` | `boolean` | `false` | Log each proxied request to terminal |
@@ -0,0 +1,3 @@
1
+ import { DirConfig, DiscoveredModule } from './types';
2
+ export declare function discoverModules(dirs?: (string | DirConfig)[]): DiscoveredModule[];
3
+ //# sourceMappingURL=discovery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3D,wBAAgB,eAAe,CAAC,IAAI,GAAE,CAAC,MAAM,GAAG,SAAS,CAAC,EAAO,GAAG,gBAAgB,EAAE,CAiDrF"}
@@ -0,0 +1,10 @@
1
+ import { Plugin } from 'vite';
2
+ import { LwcVitePluginOptions } from './types';
3
+ import * as builtinProviders from "./providers/index";
4
+ export type { Provider, LwcVitePluginOptions, PassthroughRule, DiscoveredModule, DirConfig, } from './types';
5
+ export { builtinProviders as builtins };
6
+ export { discoverModules } from './discovery';
7
+ export { lwcProxy } from './plugins/proxy';
8
+ export type { LwcProxyOptions } from './plugins/proxy';
9
+ export default function lwcVitePlugin(options?: LwcVitePluginOptions): Plugin[];
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAOnC,OAAO,KAAK,gBAAgB,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,oBAAoB,EAA8B,MAAM,SAAS,CAAC;AAEhF,YAAY,EACX,QAAQ,EACR,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,SAAS,GACT,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,gBAAgB,IAAI,QAAQ,EAAE,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,YAAY,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AA6BvD,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,OAAO,GAAE,oBAAyB,GAAG,MAAM,EAAE,CAgJlF"}