@remix-run/assets 0.6.0 → 0.7.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 +101 -13
- package/dist/assets.d.ts +2 -1
- package/dist/assets.d.ts.map +1 -1
- package/dist/lib/asset-server.d.ts +41 -19
- package/dist/lib/asset-server.d.ts.map +1 -1
- package/dist/lib/asset-server.js +98 -41
- package/dist/lib/compilation-error.d.ts +1 -1
- package/dist/lib/compilation-error.d.ts.map +1 -1
- package/dist/lib/files/compiler.d.ts +1 -1
- package/dist/lib/files/compiler.d.ts.map +1 -1
- package/dist/lib/files/compiler.js +26 -29
- package/dist/lib/files/config.d.ts +6 -0
- package/dist/lib/files/config.d.ts.map +1 -1
- package/dist/lib/files/config.js +9 -0
- package/dist/lib/fingerprint.d.ts +0 -4
- package/dist/lib/fingerprint.d.ts.map +1 -1
- package/dist/lib/fingerprint.js +0 -4
- package/dist/lib/hmr.d.ts +7 -0
- package/dist/lib/hmr.d.ts.map +1 -1
- package/dist/lib/hmr.js +198 -25
- package/dist/lib/routes.d.ts +1 -0
- package/dist/lib/routes.d.ts.map +1 -1
- package/dist/lib/routes.js +1 -1
- package/dist/lib/scripts/compiler.d.ts +8 -2
- package/dist/lib/scripts/compiler.d.ts.map +1 -1
- package/dist/lib/scripts/compiler.js +186 -36
- package/dist/lib/scripts/emit.d.ts +2 -1
- package/dist/lib/scripts/emit.d.ts.map +1 -1
- package/dist/lib/scripts/emit.js +25 -16
- package/dist/lib/scripts/resolve.d.ts +7 -1
- package/dist/lib/scripts/resolve.d.ts.map +1 -1
- package/dist/lib/scripts/resolve.js +110 -3
- package/dist/lib/scripts/specifiers.d.ts +2 -0
- package/dist/lib/scripts/specifiers.d.ts.map +1 -0
- package/dist/lib/scripts/specifiers.js +9 -0
- package/dist/lib/scripts/transform.d.ts +2 -3
- package/dist/lib/scripts/transform.d.ts.map +1 -1
- package/dist/lib/scripts/transform.js +2 -16
- package/dist/lib/styles/compiler.d.ts +0 -1
- package/dist/lib/styles/compiler.d.ts.map +1 -1
- package/dist/lib/styles/compiler.js +105 -25
- package/dist/lib/styles/emit.d.ts +2 -1
- package/dist/lib/styles/emit.d.ts.map +1 -1
- package/dist/lib/styles/emit.js +12 -10
- package/dist/lib/styles/resolve.d.ts +0 -1
- package/dist/lib/styles/resolve.d.ts.map +1 -1
- package/dist/lib/styles/resolve.js +0 -1
- package/dist/lib/styles/transform.d.ts +0 -2
- package/dist/lib/styles/transform.d.ts.map +1 -1
- package/dist/lib/styles/transform.js +0 -7
- package/dist/lib/virtual-store.d.ts +8 -0
- package/dist/lib/virtual-store.d.ts.map +1 -0
- package/dist/lib/virtual-store.js +100 -0
- package/package.json +6 -5
- package/src/assets.ts +7 -1
- package/src/lib/asset-server.ts +175 -73
- package/src/lib/compilation-error.ts +1 -0
- package/src/lib/files/compiler.ts +30 -40
- package/src/lib/files/config.ts +17 -0
- package/src/lib/fingerprint.ts +0 -9
- package/src/lib/hmr.ts +210 -26
- package/src/lib/routes.ts +1 -1
- package/src/lib/scripts/compiler.ts +238 -52
- package/src/lib/scripts/emit.ts +34 -19
- package/src/lib/scripts/resolve.ts +166 -4
- package/src/lib/scripts/specifiers.ts +11 -0
- package/src/lib/scripts/transform.ts +4 -23
- package/src/lib/styles/compiler.ts +137 -39
- package/src/lib/styles/emit.ts +18 -13
- package/src/lib/styles/resolve.ts +0 -2
- package/src/lib/styles/transform.ts +0 -10
- package/src/lib/virtual-store.ts +124 -0
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ Fetch-based server for compiling browser assets on demand.
|
|
|
10
10
|
- **Preloads** - Generate preload URLs for scripts and styles based on imports
|
|
11
11
|
- **Inspection** - List browser-reachable assets and explain URL-to-file mappings
|
|
12
12
|
- **Caching** - Conservative caching by default with stable URLs, ETags, and revalidation
|
|
13
|
-
- **Optional Fingerprinting** -
|
|
13
|
+
- **Optional Fingerprinting** - Content-based fingerprinted URLs for long-lived browser caching
|
|
14
14
|
- **Source Maps** - Serve inline or external sourcemaps
|
|
15
15
|
- **Hot Module Reloading** - Handle live code updates in development
|
|
16
16
|
- **Script Loaders** - Post-process compiled JavaScript with Node-compatible loaders
|
|
@@ -164,6 +164,8 @@ let assetServer = createAssetServer({
|
|
|
164
164
|
})
|
|
165
165
|
```
|
|
166
166
|
|
|
167
|
+
Package managers that install outside `rootDir`, such as pnpm's global virtual store, are handled without configuration: the asset server reads the store location from the nearest `node_modules/.modules.yaml` and mounts it internally so those package files still resolve to public URLs. A store that a configured mount already covers, such as pnpm's default `node_modules/.pnpm`, is left alone.
|
|
168
|
+
|
|
167
169
|
### File watching
|
|
168
170
|
|
|
169
171
|
The file system is watched by default so source changes are picked up without requiring a server restart.
|
|
@@ -212,13 +214,68 @@ let assetServer = createAssetServer({
|
|
|
212
214
|
})
|
|
213
215
|
```
|
|
214
216
|
|
|
217
|
+
## Script Entries
|
|
218
|
+
|
|
219
|
+
Use `assetServer.getScriptEntry()` to get everything needed to load a script and its dependencies.
|
|
220
|
+
|
|
221
|
+
```ts
|
|
222
|
+
let { href, importMap, preloads } = await assetServer.getScriptEntry('app/assets/entry.tsx')
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
This can be used when rendering a document shell:
|
|
226
|
+
|
|
227
|
+
```tsx
|
|
228
|
+
import type { Handle, RemixNode } from 'remix/ui'
|
|
229
|
+
import { ImportMap } from 'remix/ui/server'
|
|
230
|
+
import { assetServer } from './assets.ts'
|
|
231
|
+
|
|
232
|
+
let { href, importMap, preloads } = await assetServer.getScriptEntry('app/assets/entry.tsx')
|
|
233
|
+
|
|
234
|
+
export function Document(handle: Handle<{ children: RemixNode }>) {
|
|
235
|
+
return () => (
|
|
236
|
+
<html>
|
|
237
|
+
<head>
|
|
238
|
+
{/* ... */}
|
|
239
|
+
<ImportMap value={importMap} />
|
|
240
|
+
{preloads.map((preload) => (
|
|
241
|
+
<link rel="modulepreload" href={preload} />
|
|
242
|
+
))}
|
|
243
|
+
<script type="module" src={href} />
|
|
244
|
+
</head>
|
|
245
|
+
<body>{handle.props.children}</body>
|
|
246
|
+
</html>
|
|
247
|
+
)
|
|
248
|
+
}
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
This can also be used for resolved client entries in [`remix/ui`](https://github.com/remix-run/remix/tree/main/packages/ui) when using `import.meta.url` as the client entry ID:
|
|
252
|
+
|
|
253
|
+
```tsx
|
|
254
|
+
import { renderToStream } from 'remix/ui/server'
|
|
255
|
+
import { assetServer } from './assets.ts'
|
|
256
|
+
|
|
257
|
+
let stream = renderToStream(<App />, {
|
|
258
|
+
async resolveClientEntry(entryId, component) {
|
|
259
|
+
let { href, importMap, preloads } = await assetServer.getScriptEntry(entryId)
|
|
260
|
+
|
|
261
|
+
return {
|
|
262
|
+
href,
|
|
263
|
+
importMap,
|
|
264
|
+
preloads,
|
|
265
|
+
exportName: entryId.split('#')[1] || component.name,
|
|
266
|
+
}
|
|
267
|
+
},
|
|
268
|
+
// ...
|
|
269
|
+
})
|
|
270
|
+
```
|
|
271
|
+
|
|
215
272
|
## Hrefs
|
|
216
273
|
|
|
217
274
|
Use `assetServer.getHref()` when you need the public URL for a served asset. You can provide a root-relative or absolute file path, or a `file://` URL.
|
|
218
275
|
|
|
219
276
|
```ts
|
|
220
|
-
let src = await assetServer.getHref('app/
|
|
221
|
-
// '/assets/app/
|
|
277
|
+
let src = await assetServer.getHref('app/media/public/logo.svg')
|
|
278
|
+
// '/assets/app/media/public/logo.svg'
|
|
222
279
|
```
|
|
223
280
|
|
|
224
281
|
## Inspection
|
|
@@ -244,6 +301,16 @@ let src = await assetServer.getHref('app/media/public/image.png', {
|
|
|
244
301
|
// '/assets/app/media/public/image.png?transform=resize%3A100x100&transform=webp'
|
|
245
302
|
```
|
|
246
303
|
|
|
304
|
+
## Import Maps
|
|
305
|
+
|
|
306
|
+
Scripts retain their imports as authored and rely on import maps for resolution in the browser. `assetServer.getScriptEntry()` returns the import map for a single rendered script entry. Use `assetServer.getImportMap()` directly when you need to generate a combined import map for multiple script roots or other custom graph-level behavior.
|
|
307
|
+
|
|
308
|
+
```ts
|
|
309
|
+
let importMap = await assetServer.getImportMap(['app/assets/entry.tsx', 'app/assets/search.tsx'])
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
Without fingerprinting, import maps resolve authored specifiers to stable asset URLs. With fingerprinting enabled, the same import maps resolve stable asset URLs to content-fingerprinted asset URLs.
|
|
313
|
+
|
|
247
314
|
## Preloads
|
|
248
315
|
|
|
249
316
|
Use `assetServer.getPreloads()` when rendering HTML so you can turn the returned URLs into `<link rel="modulepreload">`, stylesheet preload tags, or `Link` headers for one or more assets and their dependencies. You can provide root-relative or absolute file paths, or `file://` URLs.
|
|
@@ -266,7 +333,7 @@ let preloads = await assetServer.getPreloads([
|
|
|
266
333
|
|
|
267
334
|
By default, assets are served at stable URLs with ETags and `Cache-Control: no-cache`.
|
|
268
335
|
|
|
269
|
-
If you want clients to cache assets aggressively without revalidation, you can opt into
|
|
336
|
+
If you want clients to cache assets aggressively without revalidation, you can opt into content-based fingerprinting.
|
|
270
337
|
|
|
271
338
|
```ts
|
|
272
339
|
import { createAssetServer } from 'remix/assets'
|
|
@@ -276,15 +343,13 @@ let assetServer = createAssetServer({
|
|
|
276
343
|
allowFiles: ['app/routes.ts', 'app/**/public/**'],
|
|
277
344
|
allowPackages: ['remix'],
|
|
278
345
|
watch: false,
|
|
279
|
-
fingerprint:
|
|
280
|
-
buildId: process.env.GITHUB_SHA,
|
|
281
|
-
},
|
|
346
|
+
fingerprint: true,
|
|
282
347
|
})
|
|
283
348
|
```
|
|
284
349
|
|
|
285
350
|
When fingerprinting is enabled, assets use a `.@<fingerprint>` segment before the file extension and are served with `Cache-Control: public, max-age=31536000, immutable`.
|
|
286
351
|
|
|
287
|
-
|
|
352
|
+
Fingerprints are based on emitted asset contents. This allows unchanged assets to keep the same URL across deployments, but it assumes that files on disk won't change after a URL is generated, so fingerprinting requires `watch: false`.
|
|
288
353
|
|
|
289
354
|
## Target
|
|
290
355
|
|
|
@@ -542,11 +607,9 @@ let assetServer = createAssetServer({
|
|
|
542
607
|
|
|
543
608
|
#### File transform caching
|
|
544
609
|
|
|
545
|
-
Use `files.cache` to store transformed file outputs via a [`file-storage`](https://github.com/remix-run/remix/tree/main/packages/file-storage) backend.
|
|
546
|
-
|
|
547
|
-
Without `files.cache`, transformed file outputs are recomputed per request.
|
|
610
|
+
Use `files.cache` to store transformed file outputs via a [`file-storage`](https://github.com/remix-run/remix/tree/main/packages/file-storage) backend. Without `files.cache`, transformed file outputs are recomputed per request.
|
|
548
611
|
|
|
549
|
-
|
|
612
|
+
`files.cacheKey` scopes transformed file cache entries. Use a stable identifier, such as a commit SHA, when you want unchanged transformed files to be reused across server restarts for the same build.
|
|
550
613
|
|
|
551
614
|
```ts
|
|
552
615
|
import * as path from 'node:path'
|
|
@@ -559,6 +622,7 @@ let assetServer = createAssetServer({
|
|
|
559
622
|
allowPackages: ['remix'],
|
|
560
623
|
files: {
|
|
561
624
|
cache: createFsFileStorage(path.resolve('.tmp/assets-cache')),
|
|
625
|
+
cacheKey: process.env.GIT_COMMIT_SHA,
|
|
562
626
|
extensions: ['.svg', '.png', '.jpg', '.jpeg', '.woff2'],
|
|
563
627
|
transforms: {
|
|
564
628
|
/*...*/
|
|
@@ -647,7 +711,7 @@ let isDevelopment = process.env.NODE_ENV === 'development'
|
|
|
647
711
|
let assetServer = createAssetServer({
|
|
648
712
|
basePath: '/assets',
|
|
649
713
|
allowFiles: ['app/routes.ts', 'app/**/public/**'],
|
|
650
|
-
|
|
714
|
+
allowPackages: ['remix'],
|
|
651
715
|
hmr: isDevelopment
|
|
652
716
|
? async () => (await import('remix/node-hmr/runtime')).createBrowserHmrChannel()
|
|
653
717
|
: undefined,
|
|
@@ -655,6 +719,30 @@ let assetServer = createAssetServer({
|
|
|
655
719
|
})
|
|
656
720
|
```
|
|
657
721
|
|
|
722
|
+
Use `moduleImporter` to customize how HMR dynamically imports updated browser modules. It is resolved relative to the asset server's root directory and must point to a browser module exporting:
|
|
723
|
+
|
|
724
|
+
```ts
|
|
725
|
+
export function importModule(specifier: string, parentUrl: string): Promise<Record<string, unknown>>
|
|
726
|
+
```
|
|
727
|
+
|
|
728
|
+
HMR appends mappings for updated modules to the document in additional `<script type="importmap">` elements. Use `remix/multiple-import-maps-polyfill` when these updates must work in browsers without native support for multiple import maps:
|
|
729
|
+
|
|
730
|
+
```ts
|
|
731
|
+
import { createAssetServer } from 'remix/assets'
|
|
732
|
+
import { createBrowserHmrChannel } from 'remix/node-hmr/runtime'
|
|
733
|
+
|
|
734
|
+
let assetServer = createAssetServer({
|
|
735
|
+
basePath: '/assets',
|
|
736
|
+
allowFiles: ['app/routes.ts', 'app/**/public/**'],
|
|
737
|
+
allowPackages: ['remix'],
|
|
738
|
+
hmr: {
|
|
739
|
+
channel: createBrowserHmrChannel,
|
|
740
|
+
moduleImporter: 'remix/multiple-import-maps-polyfill',
|
|
741
|
+
},
|
|
742
|
+
watch: true,
|
|
743
|
+
})
|
|
744
|
+
```
|
|
745
|
+
|
|
658
746
|
### `import.meta.hot`
|
|
659
747
|
|
|
660
748
|
The `import.meta.hot` API provided by `assets` is a small runtime contract for modules that can handle updates without reloading the page. It is primarily intended for browser modules compiled by `assets`, but it can also be used directly.
|
package/dist/assets.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export { createAssetServer } from './lib/asset-server.ts';
|
|
2
2
|
export { defineFileTransform } from './lib/files/config.ts';
|
|
3
3
|
export type { AssetAccessDetails, AssetAccessRule } from './lib/access.ts';
|
|
4
|
-
export type { AssetServer, AssetServerOptions, BrowserHmrChannel } from './lib/asset-server.ts';
|
|
4
|
+
export type { AssetServer, AssetServerOptions, BrowserHmrChannel, ScriptEntry, } from './lib/asset-server.ts';
|
|
5
5
|
export type { AssetDetails, AssetKind, AssetStatus } from './lib/inspection.ts';
|
|
6
|
+
export type { ScriptImportMap } from './lib/scripts/compiler.ts';
|
|
6
7
|
export type { ModuleLoader } from './lib/loaders.ts';
|
|
7
8
|
//# sourceMappingURL=assets.d.ts.map
|
package/dist/assets.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assets.d.ts","sourceRoot":"","sources":["../src/assets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAC3D,YAAY,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAC1E,YAAY,
|
|
1
|
+
{"version":3,"file":"assets.d.ts","sourceRoot":"","sources":["../src/assets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAC3D,YAAY,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAC1E,YAAY,EACV,WAAW,EACX,kBAAkB,EAClB,iBAAiB,EACjB,WAAW,GACZ,MAAM,uBAAuB,CAAA;AAC9B,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAC/E,YAAY,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAChE,YAAY,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AssetRequestTransformMap, AssetServerFilesOptions, AssetTransformInvocation } from './files/config.ts';
|
|
2
2
|
import type { HmrPayload } from './hmr.ts';
|
|
3
3
|
import type { ModuleLoader } from './loaders.ts';
|
|
4
|
-
import type { ScriptHmrUpdate } from './scripts/compiler.ts';
|
|
4
|
+
import type { ScriptHmrUpdate, ScriptImportMap } from './scripts/compiler.ts';
|
|
5
5
|
import type { AssetTarget } from './target.ts';
|
|
6
6
|
import { type AssetDetails } from './inspection.ts';
|
|
7
7
|
import type { ChokidarWatcher } from './watch.ts';
|
|
@@ -57,6 +57,17 @@ export interface BrowserHmrChannel {
|
|
|
57
57
|
* @returns A channel, no channel, or a promise for either result.
|
|
58
58
|
*/
|
|
59
59
|
export type BrowserHmrChannelFactory = () => BrowserHmrChannel | undefined | Promise<BrowserHmrChannel | undefined>;
|
|
60
|
+
/** Browser HMR integration options. */
|
|
61
|
+
export interface BrowserHmrOptions {
|
|
62
|
+
/** Creates the channel that delivers browser HMR events. */
|
|
63
|
+
channel: BrowserHmrChannelFactory;
|
|
64
|
+
/**
|
|
65
|
+
* Module specifier resolved relative to the asset server's root directory. It must point to a
|
|
66
|
+
* browser module exporting `importModule(specifier, parentUrl)` for evaluating JavaScript updates.
|
|
67
|
+
* The module and its dependencies must be allowed and reachable through configured mounts.
|
|
68
|
+
*/
|
|
69
|
+
moduleImporter?: string;
|
|
70
|
+
}
|
|
60
71
|
/**
|
|
61
72
|
* Converts a watcher batch into ordered browser update or reload events.
|
|
62
73
|
*
|
|
@@ -86,38 +97,30 @@ export type BrowserHmrFileEvent = {
|
|
|
86
97
|
* Browser HMR event emitted to connected clients.
|
|
87
98
|
*/
|
|
88
99
|
export type BrowserHmrEvent = {
|
|
100
|
+
/** Consumer-owned data keyed by a stable, versioned namespace. */
|
|
101
|
+
data: Record<string, BrowserHmrData>;
|
|
89
102
|
/** Absolute source file paths that triggered this update. */
|
|
90
103
|
files?: string[];
|
|
91
|
-
/** Update time used to bypass browser module and stylesheet caches. */
|
|
92
|
-
timestamp: number;
|
|
93
104
|
/** Browser update event. */
|
|
94
105
|
type: 'update';
|
|
95
|
-
/** Accepted JavaScript and CSS module updates for the browser to apply in place. */
|
|
96
|
-
updates: Extract<HmrPayload, {
|
|
97
|
-
type: 'browser:update';
|
|
98
|
-
}>['updates'];
|
|
99
106
|
} | {
|
|
100
107
|
/** Absolute source file paths that could not be handled in place. */
|
|
101
108
|
files?: string[];
|
|
102
109
|
/** Browser reload event. */
|
|
103
110
|
type: 'reload';
|
|
104
111
|
};
|
|
105
|
-
interface FingerprintOptions {
|
|
106
|
-
/**
|
|
107
|
-
* Per-build invalidation token that must change whenever fingerprinted asset URLs
|
|
108
|
-
* should be invalidated together.
|
|
109
|
-
*/
|
|
110
|
-
buildId: string;
|
|
111
|
-
}
|
|
112
112
|
type AssetSourceMaps = 'inline' | 'external';
|
|
113
113
|
type AssetSourceMapSourcePaths = 'url' | 'absolute';
|
|
114
|
+
type BrowserHmrData = null | boolean | number | string | BrowserHmrData[] | {
|
|
115
|
+
[key: string]: BrowserHmrData;
|
|
116
|
+
};
|
|
114
117
|
interface AssetServerScriptOptions {
|
|
115
118
|
/**
|
|
116
119
|
* Replace global expressions with constant values during transform, e.g.
|
|
117
120
|
* `{ 'process.env.NODE_ENV': '"production"' }`
|
|
118
121
|
*/
|
|
119
122
|
define?: Record<string, string>;
|
|
120
|
-
/** Import specifiers to
|
|
123
|
+
/** Import specifiers to treat as external dependencies (CDN URLs, import map entries, etc.) */
|
|
121
124
|
external?: string[];
|
|
122
125
|
/**
|
|
123
126
|
* Synchronous loaders that post-process compiled JavaScript.
|
|
@@ -162,12 +165,12 @@ export interface AssetServerOptions<transforms extends AssetRequestTransformMap
|
|
|
162
165
|
*/
|
|
163
166
|
denyFiles?: readonly string[];
|
|
164
167
|
/**
|
|
165
|
-
* Controls optional
|
|
168
|
+
* Controls optional content-based URL fingerprinting for served asset URLs.
|
|
166
169
|
*
|
|
167
170
|
* When omitted, all served assets use stable non-fingerprinted URLs with `Cache-Control: no-cache`.
|
|
168
171
|
* Cannot be used together with active watch mode. Set `watch: false` when fingerprinting.
|
|
169
172
|
*/
|
|
170
|
-
fingerprint?:
|
|
173
|
+
fingerprint?: boolean;
|
|
171
174
|
/**
|
|
172
175
|
* Shared compatibility target for scripts and styles. Browser targets apply to both
|
|
173
176
|
* pipelines, and `es` only affects scripts.
|
|
@@ -205,7 +208,7 @@ export interface AssetServerOptions<transforms extends AssetRequestTransformMap
|
|
|
205
208
|
* HMR requires `watch` to be enabled. The factory is called once for this asset server. Returning
|
|
206
209
|
* `undefined` leaves HMR inactive; a returned channel is closed by `assetServer.close()`.
|
|
207
210
|
*/
|
|
208
|
-
hmr?: BrowserHmrChannelFactory;
|
|
211
|
+
hmr?: BrowserHmrChannelFactory | BrowserHmrOptions;
|
|
209
212
|
/**
|
|
210
213
|
* Enable filesystem-backed cache invalidation for long-lived server instances.
|
|
211
214
|
* Enabled by default. Pass `true` to use the default watcher options, an options
|
|
@@ -226,6 +229,17 @@ type AssetServerCreateOptions<transforms extends AssetRequestTransformMap> = Omi
|
|
|
226
229
|
export type AssetServerGetHrefOptions<transforms extends AssetRequestTransformMap> = undefined | {
|
|
227
230
|
transform: readonly AssetTransformInvocation<transforms>[];
|
|
228
231
|
};
|
|
232
|
+
/**
|
|
233
|
+
* Metadata needed to render or load a script entry module.
|
|
234
|
+
*/
|
|
235
|
+
export interface ScriptEntry {
|
|
236
|
+
/** Public URL for the script entry module. */
|
|
237
|
+
href: string;
|
|
238
|
+
/** Public URLs that should be emitted as `modulepreload` hints for this script graph. */
|
|
239
|
+
preloads: string[];
|
|
240
|
+
/** Import map entries required to resolve this script graph in the browser. */
|
|
241
|
+
importMap: ScriptImportMap;
|
|
242
|
+
}
|
|
229
243
|
/**
|
|
230
244
|
* Serves compiled scripts and styles for asset requests routed to it.
|
|
231
245
|
* Construct with {@link createAssetServer}.
|
|
@@ -240,10 +254,18 @@ export interface AssetServer<transforms extends AssetRequestTransformMap = {}> {
|
|
|
240
254
|
* Returns the request href for a served asset file.
|
|
241
255
|
*/
|
|
242
256
|
getHref(filePath: string, options?: AssetServerGetHrefOptions<transforms>): Promise<string>;
|
|
257
|
+
/**
|
|
258
|
+
* Returns the href, preload URLs, and import map for a script entry module.
|
|
259
|
+
*/
|
|
260
|
+
getScriptEntry(filePath: string): Promise<ScriptEntry>;
|
|
243
261
|
/**
|
|
244
262
|
* Returns preload URLs for one or more served asset files, ordered shallowest-first.
|
|
245
263
|
*/
|
|
246
264
|
getPreloads(filePath: string | readonly string[]): Promise<string[]>;
|
|
265
|
+
/**
|
|
266
|
+
* Returns an import map for one or more script entry modules.
|
|
267
|
+
*/
|
|
268
|
+
getImportMap(filePath: string | readonly string[]): Promise<ScriptImportMap>;
|
|
247
269
|
/**
|
|
248
270
|
* Returns diagnostic details about one public asset URL or file path, including the matched mount
|
|
249
271
|
* roots, access rules, file type, and browser-reachability status.
|
|
@@ -267,7 +289,7 @@ export declare function getInternalWatchTargets<transforms extends AssetRequestT
|
|
|
267
289
|
* Create an asset server instance
|
|
268
290
|
*
|
|
269
291
|
* Compiles TypeScript/JavaScript scripts and CSS styles on demand with optional
|
|
270
|
-
*
|
|
292
|
+
* content-based URL fingerprinting, caching, and configurable directory mounts.
|
|
271
293
|
*
|
|
272
294
|
* @param options Server configuration
|
|
273
295
|
* @returns A {@link AssetServer} with `fetch()`, `getHref()`, and `getPreloads()` methods
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asset-server.d.ts","sourceRoot":"","sources":["../../src/lib/asset-server.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACV,wBAAwB,EACxB,uBAAuB,EACvB,wBAAwB,EAEzB,MAAM,mBAAmB,CAAA;AAG1B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAE1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAKhD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"asset-server.d.ts","sourceRoot":"","sources":["../../src/lib/asset-server.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACV,wBAAwB,EACxB,uBAAuB,EACvB,wBAAwB,EAEzB,MAAM,mBAAmB,CAAA;AAG1B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAE1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAKhD,OAAO,KAAK,EA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