@salesforce/vite-plugin-ui-bundle 12.17.0 → 12.18.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 CHANGED
@@ -85,8 +85,8 @@ accepts the same option.
85
85
  ```json
86
86
  {
87
87
  "manifestVersion": 1,
88
- "entry": "assets/routes-3f9a.js",
89
- "entryCss": ["assets/routes-8c1d.css"],
88
+ "entry": "assets/routes-Da6y3Zy7.js",
89
+ "entryCss": ["assets/routes-BmT0x_3c.css"],
90
90
  "externals": ["react", "react/jsx-runtime"],
91
91
  "peerDependencies": { "react": "^19.0.0" },
92
92
  "uiBundle": {
@@ -97,7 +97,8 @@ accepts the same option.
97
97
  },
98
98
  "version": "1.2.0",
99
99
  "files": [
100
- { "path": "assets/routes-3f9a.js", "md5": "…", "size": 1234 },
100
+ { "path": "assets/routes-Da6y3Zy7.js", "md5": "…", "size": 1234 },
101
+ { "path": "favicon.ico", "md5": "…", "size": 4286, "cache": "revalidate" },
101
102
  { "path": "index.html", "md5": "…", "size": 512 }
102
103
  ]
103
104
  }
@@ -113,6 +114,27 @@ accepts the same option.
113
114
  | `uiBundle` | A copy of the bundle's `ui-bundle.json`, every key as written, so Core fetches one file per version. Absent without one. |
114
115
  | `version` | The `version` option, else the bundle's package.json `version`. |
115
116
  | `files` | Every regular file in the output directory when the manifest is written, except the manifest, with `md5` and `size`. Core derives each file's content type from its extension. |
117
+ | `files[].cache` | `"revalidate"` on each non-HTML file the build can't prove is content-hashed (see below). Absent on hashed files and HTML. |
118
+
119
+ Core serves a UI bundle's non-HTML files as immutable for a year, so a file
120
+ whose bytes change under the same name would stay stale in browsers. `cache:
121
+ "revalidate"` tells Core to serve that file `public,no-cache` with an ETag
122
+ instead. A file counts as hashed only if it's part of this build and:
123
+
124
+ - for a chunk, the bundler put a content hash in its name, whether the name
125
+ came from a string or a function `entryFileNames` or `chunkFileNames`;
126
+ - for an asset, `assetFileNames` named it, from a string or a function, with a
127
+ pattern that has `[hash]` or `[hash:N]`. An asset emitted with an explicit
128
+ `fileName`, such as a sourcemap, isn't hashed whatever its name.
129
+
130
+ Vite's defaults qualify, so with a default config only the files copied from
131
+ `public/`, sourcemaps, and files written under a fixed name (by Vite, such as
132
+ `.vite/manifest.json`, or by other plugins) are marked. Put files that must
133
+ keep their URL while their content changes, such as `sw.js`,
134
+ `manifest.webmanifest`, `favicon.ico` or `robots.txt`, in `public/`. A plugin
135
+ that changes a file's bytes in `generateBundle`, after its name is hashed,
136
+ isn't caught. Marking a hashed file costs a 304
137
+ per revalidation, never stale content, so the build errs toward marking.
116
138
 
117
139
  | Option | Default | Meaning |
118
140
  | --------- | ---------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
@@ -187,3 +209,29 @@ The build removes an earlier `ui-bundle.build.json` before it writes any file,
187
209
  so a build that fails leaves none behind. To build a bundle for Core without
188
210
  changing dev or test builds, turn the option on for production only:
189
211
  `buildManifest: mode === "production"`.
212
+
213
+ ## Single-file output
214
+
215
+ Set `singleFile: true` to emit one self-contained `index.html` at build time
216
+ (required for MCP apps). Requires
217
+ [`vite-plugin-singlefile`](https://github.com/richardtallent/vite-plugin-singlefile).
218
+ It is applied to `vite build` only. Defaults to `false`. Works with both the
219
+ generic and `./site` entries.
220
+
221
+ Inlined: JS, CSS, imported assets, and plain JSX `src/assets/...` string
222
+ literals (e.g. `<img src="src/assets/images/logo.png">`, which the build imports
223
+ so Vite inlines it once, however often it is referenced). Not inlined: `public/`
224
+ files (copied as separate files; the build warns listing every copied file:
225
+ import them from `src/` to inline) and SVG `#fragment` refs such as
226
+ `<use href="src/assets/images/icons.svg#a">` (a `data:` URL can't serve `<use>`),
227
+ which are emitted as separate files with a build warning. Paths in template
228
+ literals or variables aren't traced, so import those assets explicitly.
229
+
230
+ Note: an `<a href>` to an inlined asset becomes a `data:` link, which browsers
231
+ block for top-level navigation unless the anchor has a `download` attribute.
232
+ Single-file output can also be large.
233
+
234
+ ```ts
235
+ import uiBundlePlugin from "@salesforce/vite-plugin-ui-bundle";
236
+ export default defineConfig({ plugins: [uiBundlePlugin({ singleFile: true })] });
237
+ ```
@@ -11,6 +11,15 @@ import { Plugin } from 'vite';
11
11
  *
12
12
  * `apply: "build"` + `enforce: "pre"`: no-op under `vite serve`, and runs before
13
13
  * esbuild's JSX transform so it still sees JSX attribute syntax.
14
+ *
15
+ * With `inline: true` (set by the `singleFile` option) nothing is emitted: the
16
+ * module instead gets `import _sfAsset from "./<relative path>"` and the attr
17
+ * references that binding, so Vite's asset pipeline handles it (vite-plugin-singlefile
18
+ * forces it to inline as a data URI, once per asset). The exception is an SVG
19
+ * `#fragment` ref (`<use href="icons.svg#a">`): a data URL can't serve `<use>`, so
20
+ * it is still emitted as a file and a warning is logged.
14
21
  */
15
- export declare function createAssetRefTracerPlugin(): Plugin;
22
+ export declare function createAssetRefTracerPlugin({ inline }?: {
23
+ inline?: boolean;
24
+ }): Plugin;
16
25
  //# sourceMappingURL=assetRefTracer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"assetRefTracer.d.ts","sourceRoot":"","sources":["../../src/core/assetRefTracer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAUH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAyKnC;;;;;;;;;;;;GAYG;AACH,wBAAgB,0BAA0B,IAAI,MAAM,CA8EnD"}
1
+ {"version":3,"file":"assetRefTracer.d.ts","sourceRoot":"","sources":["../../src/core/assetRefTracer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAUH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAgOnC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,0BAA0B,CAAC,EAAE,MAAc,EAAE,GAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAO,GAAG,MAAM,CA8FhG"}
@@ -1,5 +1,5 @@
1
1
  import { UIBundleManifest } from '@salesforce/ui-bundle/app';
2
- import { Plugin } from 'vite';
2
+ import { Plugin, Rollup } from 'vite';
3
3
  /** File name Core reads the build manifest from, at the root of the build output. */
4
4
  export declare const BUILD_MANIFEST_FILE = "ui-bundle.build.json";
5
5
  /**
@@ -39,6 +39,13 @@ export interface UiBundleBuildFile {
39
39
  md5: string;
40
40
  /** Size in bytes. Informational: Core doesn't check it. */
41
41
  size: number;
42
+ /**
43
+ * `"revalidate"` when the build can't prove the file is content-hashed, i.e.
44
+ * that its name changes whenever its bytes do. Core then serves it
45
+ * `public,no-cache` with an ETag instead of immutable for a year. Absent for
46
+ * hashed files and HTML. See `hashedFiles`.
47
+ */
48
+ cache?: "revalidate";
42
49
  }
43
50
  /** Contents of `ui-bundle.build.json`, as Core's `UiBundleBuildManifest` reads them. */
44
51
  export interface UiBundleBuildManifest {
@@ -148,6 +155,48 @@ export declare function validateScreens(screens: unknown): string[];
148
155
  * entry.
149
156
  */
150
157
  export declare function validateComposition(composition: unknown, self?: string): string[];
158
+ /**
159
+ * Wraps `assetFileNames` so the build sees how the bundler names each asset.
160
+ * `named` maps the md5 of an asset's source to whether every pattern the
161
+ * bundler tried for it has a hash. The bundler may call `assetFileNames` for
162
+ * several assets with the same source before it picks an output name, so one
163
+ * pattern without a hash makes the digest false, and a later hashed pattern
164
+ * can't undo that. An asset emitted with an explicit `fileName` never goes
165
+ * through `assetFileNames`, so it isn't in `named`, whatever its name looks
166
+ * like.
167
+ *
168
+ * The pattern may come from a string or a function, and the bundler applies it
169
+ * to the name itself, including the number it appends to keep names unique.
170
+ */
171
+ export declare function trackAssetNames(output: Rollup.OutputOptions, named: Map<string, boolean>): Rollup.OutputOptions;
172
+ /**
173
+ * Files of `bundle` whose names change with their bytes. Vite's defaults
174
+ * pass, so with a default config every chunk and every asset Vite names is
175
+ * hashed, and only files from public/, sourcemaps and files written under a
176
+ * fixed name are not.
177
+ *
178
+ * - A chunk is hashed when the bundler put a hash in its name. Rollup and
179
+ * Rolldown name a chunk with a placeholder where the hash goes, computed
180
+ * from the chunk's final content, and keep that name as
181
+ * `preliminaryFileName`; a name without a hash is final as is. That holds
182
+ * whatever produced the name: a string option, a function, or an explicit
183
+ * `fileName` (which never has a placeholder).
184
+ * - Assets keep no such name, so an asset is hashed when `assetFileNames`
185
+ * named it (see `trackAssetNames`) with a pattern that has a hash. That
186
+ * covers a function `assetFileNames`, an unnamed asset, and a name made
187
+ * unique with a number. The record is by content, so it can't tell which
188
+ * of several output files with the same bytes `assetFileNames` named, or
189
+ * whether one of them was emitted with an explicit `fileName`. Such a
190
+ * group counts as unhashed, every file in it.
191
+ *
192
+ * A plugin that changes a file's bytes in `generateBundle`, after its name is
193
+ * hashed, is out of reach: the name stays and Core caches it as hashed.
194
+ *
195
+ * Core never infers this from a name, so the build errs the other way: a
196
+ * hashed file marked anyway costs Core a 304 on each revalidation, while an
197
+ * unhashed file served immutable stays stale for a year.
198
+ */
199
+ export declare function hashedFiles(bundle: Rollup.OutputBundle, namedAssets: ReadonlyMap<string, boolean>): Set<string>;
151
200
  /**
152
201
  * Build-only plugin for UI bundles Core composes or serves as a published
153
202
  * version. It keeps shared specifiers external, so the page's import map
@@ -163,9 +212,10 @@ export declare function validateComposition(composition: unknown, self?: string)
163
212
  * 4. `resolveId` / `load`: keep shared specifiers external.
164
213
  * 5. `renderStart`: remove a previous build's manifest.
165
214
  * 6. `generateBundle`: record `entry`, `entryCss` and `externals` from the
166
- * output chunks, fail on React's dev JSX runtime, and warn about other
167
- * bundled copies of shared packages.
168
- * 7. `writeBundle`: validate, list the files on disk and write the manifest.
215
+ * output chunks, fail on React's dev JSX runtime, warn about other
216
+ * bundled copies of shared packages, and record which files are hashed.
217
+ * 7. `writeBundle`: validate, list the files on disk, mark the unhashed ones
218
+ * and write the manifest.
169
219
  */
170
220
  export declare function createBuildManifestPlugin(options?: BuildManifestOptions): Plugin;
171
221
  //# sourceMappingURL=buildManifest.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"buildManifest.d.ts","sourceRoot":"","sources":["../../src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AK,EAAE,MAAM,GAAG,OAAO,CAUlD;AAmCD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAKjE;AAED;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAQ9C;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAE3D;AAKD;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,EAAE,CAkE1D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAwCjF;AA0DD;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAC9B,MAAM,EAAE,MAAM,CAAC,aAAa,EAC5B,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,GACzB,MAAM,CAAC,aAAa,CAWtB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,WAAW,CAC1B,MAAM,EAAE,MAAM,CAAC,YAAY,EAC3B,WAAW,EAAE,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,GACvC,GAAG,CAAC,MAAM,CAAC,CAwBb;AA+BD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,GAAE,oBAAyB,GAAG,MAAM,CAkZpF"}
@@ -13,6 +13,19 @@ interface CorePluginSharedOptions extends DesignPluginOptions {
13
13
  * {@link BuildManifestOptions}.
14
14
  */
15
15
  buildManifest?: boolean | BuildManifestOptions;
16
+ /**
17
+ * Emit a single self-contained `index.html` at build time (required for MCP apps).
18
+ * Requires `vite-plugin-singlefile`. Inlined: JS, CSS, imported assets, and plain
19
+ * JSX `src/assets/...` string literals. NOT inlined (emitted separately, with a
20
+ * build warning): `public/` files and SVG `#fragment` refs (`<use href="icons.svg#a">`).
21
+ * Paths in template literals or variables aren't traced; import those assets
22
+ * explicitly. An `<a href>` to an inlined
23
+ * asset becomes a `data:` link, which browsers block for top-level navigation
24
+ * unless the anchor has a `download` attribute. Output can be large.
25
+ *
26
+ * @default false
27
+ */
28
+ singleFile?: boolean;
16
29
  }
17
30
  /**
18
31
  * Core plugin options, modeled as a discriminated union on
@@ -1 +1 @@
1
- {"version":3,"file":"createCorePlugins.d.ts","sourceRoot":"","sources":["../../src/core/createCorePlugins.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AASH,OAAO,KAAK,EAGX,MAAM,EAGN,MAAM,MAAM,CAAC;AAYd,OAAO,EAA6B,KAAK,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvF,OAAO,EAAsB,KAAK,mBAAmB,EAAE,MAAM,UAAU,CAAC;AACxE,OAAO,EAIN,KAAK,gBAAgB,EAErB,MAAM,OAAO,CAAC;AAEf,sEAAsE;AACtE,UAAU,uBAAwB,SAAQ,mBAAmB;IAC5D,6BAA6B;IAC7B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;;;;;OAKG;IACH,aAAa,CAAC,EAAE,OAAO,GAAG,oBAAoB,CAAC;CAC/C;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,iBAAiB,GAAG,uBAAuB,GACtD,CACG;IACA,mEAAmE;IACnE,eAAe,EAAE,IAAI,CAAC;IACtB,qEAAqE;IACrE,QAAQ,CAAC,EAAE,KAAK,CAAC;CAChB,GACD;IACA,eAAe,CAAC,EAAE,KAAK,CAAC;IACxB,2BAA2B;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACjB,CACH,CAAC;AAEH;;;;;GAKG;AACH,MAAM,WAAW,SAAS;IACzB,eAAe,CAAC,EAAE,gBAAgB,CAAC;CACnC;AA0BD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAChC,OAAO,GAAE,iBAAsB,EAC/B,KAAK,GAAE,SAAc,GACnB,MAAM,EAAE,CAgTV"}
1
+ {"version":3,"file":"createCorePlugins.d.ts","sourceRoot":"","sources":["../../src/core/createCorePlugins.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAUH,OAAO,KAAK,EAGX,MAAM,EAGN,MAAM,MAAM,CAAC;AAYd,OAAO,EAA6B,KAAK,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvF,OAAO,EAAsB,KAAK,mBAAmB,EAAE,MAAM,UAAU,CAAC;AACxE,OAAO,EAIN,KAAK,gBAAgB,EAErB,MAAM,OAAO,CAAC;AAEf,sEAAsE;AACtE,UAAU,uBAAwB,SAAQ,mBAAmB;IAC5D,6BAA6B;IAC7B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;;;;;OAKG;IACH,aAAa,CAAC,EAAE,OAAO,GAAG,oBAAoB,CAAC;IAC/C;;;;;;;;;;;OAWG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,iBAAiB,GAAG,uBAAuB,GACtD,CACG;IACA,mEAAmE;IACnE,eAAe,EAAE,IAAI,CAAC;IACtB,qEAAqE;IACrE,QAAQ,CAAC,EAAE,KAAK,CAAC;CAChB,GACD;IACA,eAAe,CAAC,EAAE,KAAK,CAAC;IACxB,2BAA2B;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACjB,CACH,CAAC;AAEH;;;;;GAKG;AACH,MAAM,WAAW,SAAS;IACzB,eAAe,CAAC,EAAE,gBAAgB,CAAC;CACnC;AA0BD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAChC,OAAO,GAAE,iBAAsB,EAC/B,KAAK,GAAE,SAAc,GACnB,MAAM,EAAE,CA0TV"}
@@ -2,6 +2,7 @@ import { readFile } from "node:fs/promises";
2
2
  import path, { dirname, join, basename } from "node:path";
3
3
  import { loadManifest, getOrgInfo, loadDevProxyConfig } from "@salesforce/ui-bundle/app";
4
4
  import { injectLivePreviewScript, createProxyHandler } from "@salesforce/ui-bundle/proxy";
5
+ import { singleFilePlugins } from "@salesforce/ui-bundle/vite";
5
6
  import fs, { existsSync, readFileSync, readdirSync, rmSync, realpathSync, writeFileSync } from "node:fs";
6
7
  import { ASSETS_ROOT, resolveAssetRef, CSS_URL_TOKEN_SOURCE } from "@salesforce/ui-design-mode/authoring/host";
7
8
  import { createHash } from "node:crypto";
@@ -65,12 +66,25 @@ const ASSET_ATTRS = /* @__PURE__ */ new Set(["src", "poster", "href", "srcSet",
65
66
  const CSS_URL_TOKEN = new RegExp(CSS_URL_TOKEN_SOURCE, "gi");
66
67
  const escapeTemplateRaw = (s) => s.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${");
67
68
  const suffixOf = (raw) => raw.match(/[?#].*$/)?.[0] ?? "";
69
+ const suffixFor = (url, raw) => "importPath" in url ? raw.match(/#.*$/)?.[0] ?? "" : suffixOf(raw);
68
70
  function createTracerBabelPlugin(emit, onTouch) {
69
71
  return ({ types: t }) => {
70
- const fileUrlExpr = (referenceId) => t.memberExpression(
71
- t.metaProperty(t.identifier("import"), t.identifier("meta")),
72
- t.identifier(`ROLLUP_FILE_URL_${referenceId}`)
73
- );
72
+ let program;
73
+ const imports = /* @__PURE__ */ new Map();
74
+ const fileUrlExpr = (url) => {
75
+ if ("importPath" in url) {
76
+ let name = imports.get(url.importPath);
77
+ if (!name) {
78
+ name = program.scope.generateUidIdentifier("sfAsset").name;
79
+ imports.set(url.importPath, name);
80
+ }
81
+ return t.identifier(name);
82
+ }
83
+ return t.memberExpression(
84
+ t.metaProperty(t.identifier("import"), t.identifier("meta")),
85
+ t.identifier(`ROLLUP_FILE_URL_${url.referenceId}`)
86
+ );
87
+ };
74
88
  const withTail = (expr, tail) => tail ? t.templateLiteral(
75
89
  [
76
90
  t.templateElement({ raw: "", cooked: "" }, false),
@@ -91,13 +105,13 @@ function createTracerBabelPlugin(emit, onTouch) {
91
105
  if (!inner) continue;
92
106
  const resolved = resolveAssetRef(inner.trim());
93
107
  if (!resolved) continue;
94
- const referenceId = emit(resolved.assetPath);
95
- if (!referenceId) continue;
108
+ const assetUrl = emit(resolved.assetPath, inner.trim());
109
+ if (!assetUrl) continue;
96
110
  matched = true;
97
- buf += raw.slice(cursor, m.index) + "url(";
111
+ buf += raw.slice(cursor, m.index) + 'url("';
98
112
  quasis.push(buf);
99
- expressions.push(fileUrlExpr(referenceId));
100
- buf = suffixOf(inner.trim()) + ")";
113
+ expressions.push(fileUrlExpr(assetUrl));
114
+ buf = suffixFor(assetUrl, inner.trim()) + '")';
101
115
  cursor = m.index + m[0].length;
102
116
  }
103
117
  if (!matched) return null;
@@ -113,6 +127,25 @@ function createTracerBabelPlugin(emit, onTouch) {
113
127
  return {
114
128
  name: "asset-ref-tracer",
115
129
  visitor: {
130
+ Program: {
131
+ enter(nodePath) {
132
+ program = nodePath;
133
+ imports.clear();
134
+ },
135
+ // Single-file builds: one `import <binding> from "<asset>"` per distinct asset.
136
+ exit(nodePath) {
137
+ if (!imports.size) return;
138
+ nodePath.unshiftContainer(
139
+ "body",
140
+ [...imports].map(
141
+ ([specifier, name]) => t.importDeclaration(
142
+ [t.importDefaultSpecifier(t.identifier(name))],
143
+ t.stringLiteral(specifier)
144
+ )
145
+ )
146
+ );
147
+ }
148
+ },
116
149
  JSXAttribute(nodePath) {
117
150
  const nameNode = nodePath.node.name;
118
151
  if (!t.isJSXIdentifier(nameNode)) return;
@@ -143,21 +176,19 @@ function createTracerBabelPlugin(emit, onTouch) {
143
176
  if (!url) return;
144
177
  const resolved2 = resolveAssetRef(url);
145
178
  if (!resolved2) return;
146
- const referenceId2 = emit(resolved2.assetPath);
147
- if (!referenceId2) return;
148
- const tail = suffixOf(url) + (descriptor.length ? ` ${descriptor.join(" ")}` : "");
149
- nodePath.node.value = t.jsxExpressionContainer(
150
- withTail(fileUrlExpr(referenceId2), tail)
151
- );
179
+ const assetUrl2 = emit(resolved2.assetPath, url);
180
+ if (!assetUrl2) return;
181
+ const tail = suffixFor(assetUrl2, url) + (descriptor.length ? ` ${descriptor.join(" ")}` : "");
182
+ nodePath.node.value = t.jsxExpressionContainer(withTail(fileUrlExpr(assetUrl2), tail));
152
183
  onTouch();
153
184
  return;
154
185
  }
155
186
  const resolved = resolveAssetRef(value.value);
156
187
  if (!resolved) return;
157
- const referenceId = emit(resolved.assetPath);
158
- if (!referenceId) return;
188
+ const assetUrl = emit(resolved.assetPath, value.value);
189
+ if (!assetUrl) return;
159
190
  nodePath.node.value = t.jsxExpressionContainer(
160
- withTail(fileUrlExpr(referenceId), suffixOf(value.value))
191
+ withTail(fileUrlExpr(assetUrl), suffixFor(assetUrl, value.value))
161
192
  );
162
193
  onTouch();
163
194
  }
@@ -165,7 +196,7 @@ function createTracerBabelPlugin(emit, onTouch) {
165
196
  };
166
197
  };
167
198
  }
168
- function createAssetRefTracerPlugin() {
199
+ function createAssetRefTracerPlugin({ inline = false } = {}) {
169
200
  let root = process.cwd();
170
201
  let emitted = /* @__PURE__ */ new Map();
171
202
  return {
@@ -185,26 +216,37 @@ function createAssetRefTracerPlugin() {
185
216
  const isJsx = filepath.endsWith(".jsx");
186
217
  if (!isTsx && !isJsx) return null;
187
218
  if (filepath.includes("node_modules")) return null;
188
- const emit = (assetPath) => {
219
+ const emit = (assetPath, raw) => {
189
220
  const absPath = path.resolve(root, assetPath);
190
- if (emitted.has(absPath)) return emitted.get(absPath) ?? null;
191
- let source;
192
- try {
193
- source = fs.readFileSync(absPath);
194
- } catch {
221
+ const isSvgFragment = inline && /\.svg$/i.test(absPath) && suffixOf(raw).includes("#");
222
+ const key = isSvgFragment ? `${absPath}#` : absPath;
223
+ let referenceId = emitted.get(key);
224
+ if (referenceId === void 0) {
225
+ let source;
226
+ try {
227
+ source = fs.readFileSync(absPath);
228
+ } catch {
229
+ this.warn(
230
+ `[asset-ref-tracer] referenced asset not found, leaving literal unchanged: ${assetPath}`
231
+ );
232
+ }
233
+ if (source && (!inline || isSvgFragment)) {
234
+ this.addWatchFile(absPath);
235
+ referenceId = this.emitFile({ type: "asset", name: path.basename(assetPath), source });
236
+ } else {
237
+ referenceId = source ? "" : null;
238
+ }
239
+ emitted.set(key, referenceId);
240
+ }
241
+ if (referenceId === null) return null;
242
+ if (isSvgFragment) {
195
243
  this.warn(
196
- `[asset-ref-tracer] referenced asset not found, leaving literal unchanged: ${assetPath}`
244
+ `[asset-ref-tracer] SVG fragment refs can't be inlined in single-file builds; "${raw}" is emitted as a separate file, so the build isn't fully self-contained. Inline the <symbol> markup or import the SVG as a component.`
197
245
  );
198
- emitted.set(absPath, null);
199
- return null;
200
246
  }
201
- const referenceId = this.emitFile({
202
- type: "asset",
203
- name: path.basename(assetPath),
204
- source
205
- });
206
- emitted.set(absPath, referenceId);
207
- return referenceId;
247
+ if (!inline || isSvgFragment) return { referenceId };
248
+ const rel = path.relative(path.dirname(filepath), absPath).split(path.sep).join("/");
249
+ return { importPath: rel.startsWith(".") ? rel : `./${rel}` };
208
250
  };
209
251
  const { transformAsync } = await import("@babel/core");
210
252
  let touched = false;
@@ -443,6 +485,45 @@ function entryCss(entry, chunks) {
443
485
  visit(entry);
444
486
  return [...css];
445
487
  }
488
+ const DEFAULT_ASSET_FILE_NAMES = "assets/[name]-[hash][extname]";
489
+ const HASH_PLACEHOLDER = /\[hash(?::\d+)?\]/;
490
+ const md5Of = (source) => createHash("md5").update(source).digest("hex");
491
+ function trackAssetNames(output, named) {
492
+ const original = output.assetFileNames ?? DEFAULT_ASSET_FILE_NAMES;
493
+ return {
494
+ ...output,
495
+ assetFileNames(info) {
496
+ const pattern = typeof original === "function" ? original(info) : original;
497
+ const digest = md5Of(info.source);
498
+ named.set(digest, (named.get(digest) ?? true) && HASH_PLACEHOLDER.test(pattern));
499
+ return pattern;
500
+ }
501
+ };
502
+ }
503
+ function hashedFiles(bundle, namedAssets) {
504
+ const hashed = /* @__PURE__ */ new Set();
505
+ const files = Object.values(bundle);
506
+ const copies = /* @__PURE__ */ new Map();
507
+ for (const file of files) {
508
+ if (file.type === "asset") {
509
+ const digest = md5Of(file.source);
510
+ copies.set(digest, (copies.get(digest) ?? 0) + 1);
511
+ }
512
+ }
513
+ for (const file of files) {
514
+ if (file.type === "chunk") {
515
+ const preliminary = file.preliminaryFileName;
516
+ if (typeof preliminary === "string" && preliminary !== file.fileName) {
517
+ hashed.add(file.fileName);
518
+ }
519
+ } else {
520
+ const digest = md5Of(file.source);
521
+ if (copies.get(digest) === 1 && namedAssets.get(digest)) hashed.add(file.fileName);
522
+ }
523
+ }
524
+ return hashed;
525
+ }
526
+ const isHtml = (file) => /\.html?$/i.test(file);
446
527
  function isInside(dir, file) {
447
528
  const rel = path.relative(dir, file);
448
529
  return !rel.startsWith("..") && !path.isAbsolute(rel);
@@ -464,6 +545,7 @@ function createBuildManifestPlugin(options = {}) {
464
545
  let shared = /* @__PURE__ */ new Set();
465
546
  let sharedPackages = /* @__PURE__ */ new Set();
466
547
  let emptiesOutDir = true;
548
+ const namedAssets = /* @__PURE__ */ new Map();
467
549
  let pending;
468
550
  return {
469
551
  name: "@salesforce/vite-plugin-ui-bundle:build-manifest",
@@ -543,6 +625,11 @@ function createBuildManifestPlugin(options = {}) {
543
625
  );
544
626
  }
545
627
  },
628
+ // Watch how assetFileNames names the assets, to tell hashed ones from fixed names.
629
+ outputOptions(output) {
630
+ namedAssets.clear();
631
+ return trackAssetNames(output, namedAssets);
632
+ },
546
633
  // Remove the previous build's manifest before anything is written, so a build
547
634
  // that fails never leaves one next to its output.
548
635
  renderStart(outputOptions) {
@@ -597,11 +684,13 @@ export { exports as "module.exports" };
597
684
  const entry = chunks.find(
598
685
  (c) => c.isEntry && entryIds.has((c.facadeModuleId ?? "").replace(/\?commonjs-entry$/, ""))
599
686
  );
687
+ const hashed = hashedFiles(bundle, namedAssets);
600
688
  pending = {
601
689
  entry: entry?.fileName,
602
690
  entryCss: entry && entryCss(entry, chunks),
603
691
  // `imported` also holds the bundle's own chunks; keep only shared specifiers.
604
- externals: [...imported].filter((id) => shared.has(id)).sort()
692
+ externals: [...imported].filter((id) => shared.has(id)).sort(),
693
+ hashed
605
694
  };
606
695
  },
607
696
  // Ordered "post", so files Vite and earlier plugins write are listed too.
@@ -610,7 +699,7 @@ export { exports as "module.exports" };
610
699
  sequential: true,
611
700
  handler(outputOptions) {
612
701
  if (!pending) return;
613
- const { entry, entryCss: entryCss2, externals } = pending;
702
+ const { entry, entryCss: entryCss2, externals, hashed } = pending;
614
703
  pending = void 0;
615
704
  const dir = outputOptions.dir ? path.resolve(outputOptions.dir) : outDir;
616
705
  const pkg = readJsonIfPresent(path.join(root, "package.json")) ?? {};
@@ -690,7 +779,10 @@ export { exports as "module.exports" };
690
779
  return {
691
780
  path: file,
692
781
  md5: createHash("md5").update(bytes).digest("hex"),
693
- size: bytes.length
782
+ size: bytes.length,
783
+ // Files that aren't in the bundle (public/, other plugins', an
784
+ // earlier build's) aren't hashed by Rollup, so they're marked too.
785
+ ...!isHtml(file) && !hashed.has(file) && { cache: "revalidate" }
694
786
  };
695
787
  });
696
788
  if (skipped.length) {
@@ -1077,13 +1169,21 @@ function createCorePlugins(options = {}, hooks = {}) {
1077
1169
  }
1078
1170
  };
1079
1171
  const designPlugin = createDesignPlugin(options);
1080
- const assetRefTracerPlugin = createAssetRefTracerPlugin();
1172
+ const assetRefTracerPlugin = createAssetRefTracerPlugin({ inline: !!options.singleFile });
1081
1173
  const plugins = [designPlugin, assetRefTracerPlugin, corePlugin];
1082
1174
  if (options.buildManifest) {
1083
1175
  plugins.push(
1084
1176
  createBuildManifestPlugin(options.buildManifest === true ? {} : options.buildManifest)
1085
1177
  );
1086
1178
  }
1179
+ if (options.singleFile) {
1180
+ plugins.push(
1181
+ ...singleFilePlugins({
1182
+ owner: "@salesforce/vite-plugin-ui-bundle",
1183
+ option: "singleFile: true"
1184
+ })
1185
+ );
1186
+ }
1087
1187
  return plugins;
1088
1188
  }
1089
1189
  export {
package/dist/index.d.ts CHANGED
@@ -1,14 +1,9 @@
1
1
  import { Plugin } from 'vite';
2
2
  import { CorePluginOptions } from './core/createCorePlugins';
3
3
  export type { BasePathResolver, Environment } from './core/env';
4
- export type { CorePluginOptions, CoreHooks } from './core/createCorePlugins';
4
+ export type { CorePluginOptions, CorePluginOptions as PluginOptions, CoreHooks, } from './core/createCorePlugins';
5
5
  export type { BuildManifestOptions, UiBundleBuildFile, UiBundleBuildManifest, } from './core/buildManifest';
6
6
  export { BUILD_MANIFEST_FILE } from './core/buildManifest';
7
- /**
8
- * Options for the generic UI-bundle plugin: `orgAlias`, `debug`, `disableOrgProxy`,
9
- * `designMode`, `designModeExcludePaths`, and `buildManifest`.
10
- */
11
- export type PluginOptions = CorePluginOptions;
12
7
  /**
13
8
  * Generic UI-bundle Vite plugin.
14
9
  *
@@ -16,5 +11,5 @@ export type PluginOptions = CorePluginOptions;
16
11
  * folded in — the default for every bundle. Site bundles that need per-request
17
12
  * language folding import `@salesforce/vite-plugin-ui-bundle/site` instead.
18
13
  */
19
- export default function uiBundlePlugin(options?: PluginOptions): Plugin[];
14
+ export default function uiBundlePlugin(options?: CorePluginOptions): Plugin[];
20
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,EAAqB,KAAK,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAErF,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAChE,YAAY,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC7E,YAAY,EACX,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,GACrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAE3D;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,iBAAiB,CAAC;AAE9C;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,OAAO,GAAE,aAAkB,GAAG,MAAM,EAAE,CAG5E"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,EAAqB,KAAK,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAErF,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAChE,YAAY,EACX,iBAAiB,EACjB,iBAAiB,IAAI,aAAa,EAClC,SAAS,GACT,MAAM,0BAA0B,CAAC;AAClC,YAAY,EACX,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,GACrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAE3D;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,OAAO,GAAE,iBAAsB,GAAG,MAAM,EAAE,CAGhF"}
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { c as createCorePlugins } from "./createCorePlugins-CDMGSlej.js";
2
- import { B } from "./createCorePlugins-CDMGSlej.js";
1
+ import { c as createCorePlugins } from "./createCorePlugins-C2hhY3Xv.js";
2
+ import { B } from "./createCorePlugins-C2hhY3Xv.js";
3
3
  function uiBundlePlugin(options = {}) {
4
4
  return createCorePlugins(options);
5
5
  }
@@ -1,4 +1,4 @@
1
- import { c as createCorePlugins } from "../createCorePlugins-CDMGSlej.js";
1
+ import { c as createCorePlugins } from "../createCorePlugins-C2hhY3Xv.js";
2
2
  function resolveLanguageFromUrl(url, supported) {
3
3
  const [defaultLang, ...nonDefault] = supported;
4
4
  if (defaultLang === void 0) return void 0;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@salesforce/vite-plugin-ui-bundle",
3
3
  "description": "Vite plugin for Salesforce UI Bundles",
4
- "version": "12.17.0",
4
+ "version": "12.18.0",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "type": "module",
7
7
  "main": "./dist/index.js",
@@ -32,8 +32,8 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "@babel/core": "^7.29.6",
35
- "@salesforce/ui-bundle": "^12.17.0",
36
- "@salesforce/ui-design-mode": "12.17.0"
35
+ "@salesforce/ui-bundle": "^12.18.0",
36
+ "@salesforce/ui-design-mode": "12.18.0"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@playwright/test": "^1.63.0",
@@ -43,10 +43,17 @@
43
43
  "react-dom": "^19.3.0",
44
44
  "vite": "^7.3.7",
45
45
  "vite-plugin-dts": "^4.5.4",
46
+ "vite-plugin-singlefile": "^2.3.4",
46
47
  "vitest": "^4.1.11"
47
48
  },
48
49
  "peerDependencies": {
49
- "vite": "^7.0.0 || ^8.0.0"
50
+ "vite": "^7.0.0 || ^8.0.0",
51
+ "vite-plugin-singlefile": "^2.3.4"
52
+ },
53
+ "peerDependenciesMeta": {
54
+ "vite-plugin-singlefile": {
55
+ "optional": true
56
+ }
50
57
  },
51
58
  "engines": {
52
59
  "node": ">=20.0.0"