@remix-run/assets 0.1.0 → 0.3.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 (72) hide show
  1. package/README.md +88 -67
  2. package/dist/lib/access.d.ts.map +1 -1
  3. package/dist/lib/access.js +3 -0
  4. package/dist/lib/asset-server.d.ts +50 -45
  5. package/dist/lib/asset-server.d.ts.map +1 -1
  6. package/dist/lib/asset-server.js +159 -50
  7. package/dist/lib/compilation-error.d.ts +2 -2
  8. package/dist/lib/compilation-error.d.ts.map +1 -1
  9. package/dist/lib/compilation-error.js +1 -1
  10. package/dist/lib/file-matcher.d.ts.map +1 -1
  11. package/dist/lib/file-matcher.js +3 -2
  12. package/dist/lib/injected-packages.d.ts +11 -0
  13. package/dist/lib/injected-packages.d.ts.map +1 -0
  14. package/dist/lib/injected-packages.js +86 -0
  15. package/dist/lib/module-store.d.ts +41 -0
  16. package/dist/lib/module-store.d.ts.map +1 -0
  17. package/dist/lib/{scripts/store.js → module-store.js} +43 -41
  18. package/dist/lib/paths.d.ts +1 -0
  19. package/dist/lib/paths.d.ts.map +1 -1
  20. package/dist/lib/paths.js +12 -0
  21. package/dist/lib/routes.d.ts +5 -7
  22. package/dist/lib/routes.d.ts.map +1 -1
  23. package/dist/lib/routes.js +13 -16
  24. package/dist/lib/scripts/compiler.d.ts +15 -15
  25. package/dist/lib/scripts/compiler.d.ts.map +1 -1
  26. package/dist/lib/scripts/compiler.js +50 -46
  27. package/dist/lib/scripts/emit.js +2 -2
  28. package/dist/lib/scripts/resolve.d.ts +7 -17
  29. package/dist/lib/scripts/resolve.d.ts.map +1 -1
  30. package/dist/lib/scripts/resolve.js +47 -14
  31. package/dist/lib/scripts/transform.d.ts +11 -9
  32. package/dist/lib/scripts/transform.d.ts.map +1 -1
  33. package/dist/lib/scripts/transform.js +110 -23
  34. package/dist/lib/source-maps.d.ts +1 -1
  35. package/dist/lib/source-maps.d.ts.map +1 -1
  36. package/dist/lib/source-maps.js +7 -1
  37. package/dist/lib/styles/compiler.d.ts +52 -0
  38. package/dist/lib/styles/compiler.d.ts.map +1 -0
  39. package/dist/lib/styles/compiler.js +272 -0
  40. package/dist/lib/styles/emit.d.ts +25 -0
  41. package/dist/lib/styles/emit.d.ts.map +1 -0
  42. package/dist/lib/styles/emit.js +78 -0
  43. package/dist/lib/styles/resolve.d.ts +48 -0
  44. package/dist/lib/styles/resolve.d.ts.map +1 -0
  45. package/dist/lib/styles/resolve.js +188 -0
  46. package/dist/lib/styles/transform.d.ts +47 -0
  47. package/dist/lib/styles/transform.d.ts.map +1 -0
  48. package/dist/lib/styles/transform.js +131 -0
  49. package/dist/lib/target.d.ts +21 -0
  50. package/dist/lib/target.d.ts.map +1 -0
  51. package/dist/lib/target.js +127 -0
  52. package/package.json +13 -4
  53. package/src/lib/access.ts +2 -0
  54. package/src/lib/asset-server.ts +239 -99
  55. package/src/lib/compilation-error.ts +7 -7
  56. package/src/lib/file-matcher.ts +3 -2
  57. package/src/lib/injected-packages.ts +117 -0
  58. package/src/lib/{scripts/store.ts → module-store.ts} +100 -87
  59. package/src/lib/paths.ts +28 -0
  60. package/src/lib/routes.ts +31 -22
  61. package/src/lib/scripts/compiler.ts +88 -70
  62. package/src/lib/scripts/emit.ts +2 -2
  63. package/src/lib/scripts/resolve.ts +85 -28
  64. package/src/lib/scripts/transform.ts +153 -36
  65. package/src/lib/source-maps.ts +8 -1
  66. package/src/lib/styles/compiler.ts +400 -0
  67. package/src/lib/styles/emit.ts +137 -0
  68. package/src/lib/styles/resolve.ts +316 -0
  69. package/src/lib/styles/transform.ts +226 -0
  70. package/src/lib/target.ts +196 -0
  71. package/dist/lib/scripts/store.d.ts +0 -40
  72. package/dist/lib/scripts/store.d.ts.map +0 -1
package/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  # assets
2
2
 
3
- Fetch-based server for compiling browser JS/TS assets on demand.
3
+ Fetch-based server for compiling browser JS/TS and CSS assets on demand.
4
4
 
5
5
  ## Features
6
6
 
7
- - **On-Demand Compilation** - Compile browser assets on demand
7
+ - **On-Demand Compilation** - Compile browser scripts and styles on demand
8
8
  - **Custom File Mapping** - Define patterns for mapping public URLs to file paths on disk
9
9
  - **Access Control** - Control exactly which files can be served with allow and deny rules
10
- - **Preloads** - Generate modulepreload URLs for `<link>` tags or `Link` headers
10
+ - **Preloads** - Generate preload URLs for scripts and styles based on imports
11
11
  - **Caching** - Conservative caching by default with stable URLs, ETags, and revalidation
12
12
  - **Optional Fingerprinting** - Source-based fingerprinted URLs for long-lived browser caching
13
13
  - **Source Maps** - Serve inline or external sourcemaps
@@ -20,16 +20,17 @@ npm i remix
20
20
 
21
21
  ## Usage
22
22
 
23
- Use `createAssetServer` to serve browser modules from a URL namespace in your app.
23
+ Use `createAssetServer` to serve browser JS/TS and CSS assets from a URL namespace in your app.
24
24
 
25
25
  ```ts
26
26
  import { createRouter } from 'remix/fetch-router'
27
27
  import { createAssetServer } from 'remix/assets'
28
28
 
29
29
  let assetServer = createAssetServer({
30
+ basePath: '/assets',
30
31
  fileMap: {
31
- '/assets/app/*path': 'app/*path',
32
- '/assets/npm/*path': 'node_modules/*path',
32
+ '/app/*path': 'app/*path',
33
+ '/npm/*path': 'node_modules/*path',
33
34
  },
34
35
  allow: ['app/assets/**', 'node_modules/**'],
35
36
  })
@@ -41,7 +42,7 @@ router.get('/assets/*', ({ request }) => {
41
42
  })
42
43
  ```
43
44
 
44
- This example gives you an `/assets/*` endpoint that serves compiled browser JS modules from `app/assets` and `node_modules`.
45
+ This example gives you an `/assets/*` endpoint that serves compiled browser assets from `app/assets` and `node_modules`.
45
46
 
46
47
  ## Root Directory
47
48
 
@@ -53,9 +54,10 @@ import { createAssetServer } from 'remix/assets'
53
54
 
54
55
  let assetServer = createAssetServer({
55
56
  rootDir: path.resolve(import.meta.dirname, '..'),
57
+ basePath: '/assets',
56
58
  fileMap: {
57
- '/assets/app/*path': 'app/*path',
58
- '/assets/npm/*path': 'node_modules/*path',
59
+ '/app/*path': 'app/*path',
60
+ '/npm/*path': 'node_modules/*path',
59
61
  },
60
62
  allow: ['app/assets/**', 'node_modules/**'],
61
63
  })
@@ -69,7 +71,8 @@ You must provide an `allow` list to specify which files are allowed to be served
69
71
  import { createAssetServer } from 'remix/assets'
70
72
 
71
73
  let assetServer = createAssetServer({
72
- fileMap: { '/assets/app/*path': 'app/*path' },
74
+ basePath: '/assets',
75
+ fileMap: { '/app/*path': 'app/*path' },
73
76
  allow: ['app/assets/**'],
74
77
  deny: ['app/**/*.server.*'],
75
78
  })
@@ -79,21 +82,22 @@ Rules for `allow` and `deny` are file paths or globs. Relative values are resolv
79
82
 
80
83
  ## File Map
81
84
 
82
- Use `fileMap` to map public URLs to file paths on disk. The keys are public URL patterns, and the values are root-relative file path patterns.
85
+ Use `fileMap` to map public URLs to file paths on disk. `basePath` defines the shared public mount point, and the `fileMap` keys are URL patterns relative to that base path. The values are root-relative file path patterns.
83
86
 
84
87
  ```ts
85
88
  import { createAssetServer } from 'remix/assets'
86
89
 
87
90
  let assetServer = createAssetServer({
91
+ basePath: '/assets',
88
92
  fileMap: {
89
- '/assets/app/*path': 'app/*path',
90
- '/assets/packages/*path': '../packages/*path',
93
+ '/app/*path': 'app/*path',
94
+ '/packages/*path': '../packages/*path',
91
95
  },
92
96
  allow: ['app/assets/**', '../packages/**'],
93
97
  })
94
98
  ```
95
99
 
96
- `fileMap` entries use [`route-pattern`](https://github.com/remix-run/remix/tree/main/packages/route-pattern) syntax for both URL and file patterns. Wildcards must be named, and the same params must appear in both patterns so imports can be rewritten back to public URLs.
100
+ `fileMap` entries use [`route-pattern`](https://github.com/remix-run/remix/tree/main/packages/route-pattern) syntax for both URL and file patterns. Wildcards must be named, and the same params must appear in both patterns so imports can be rewritten back to public URLs. For example, with `basePath: '/assets'`, a `fileMap` key of `'/app/*path'` is served at `/assets/app/*path`.
97
101
 
98
102
  ### File watching
99
103
 
@@ -103,7 +107,8 @@ The file system is watched by default so source changes are picked up without re
103
107
  import { createAssetServer } from 'remix/assets'
104
108
 
105
109
  let assetServer = createAssetServer({
106
- fileMap: { '/assets/app/*path': 'app/*path' },
110
+ basePath: '/assets',
111
+ fileMap: { '/app/*path': 'app/*path' },
107
112
  allow: ['app/assets/**', 'app/node_modules/**'],
108
113
  })
109
114
  ```
@@ -120,7 +125,8 @@ You can disable file watching if the files on disk won't change, or if watching
120
125
  import { createAssetServer } from 'remix/assets'
121
126
 
122
127
  let assetServer = createAssetServer({
123
- fileMap: { '/assets/app/*path': 'app/*path' },
128
+ basePath: '/assets',
129
+ fileMap: { '/app/*path': 'app/*path' },
124
130
  allow: ['app/assets/**', 'app/node_modules/**'],
125
131
  watch: false,
126
132
  })
@@ -132,7 +138,8 @@ You can optionally provide an array of glob patterns to the `watch.ignore` optio
132
138
  import { createAssetServer } from 'remix/assets'
133
139
 
134
140
  let assetServer = createAssetServer({
135
- fileMap: { '/assets/app/*path': 'app/*path' },
141
+ basePath: '/assets',
142
+ fileMap: { '/app/*path': 'app/*path' },
136
143
  allow: ['app/assets/**', 'app/node_modules/**'],
137
144
  watch: {
138
145
  ignore: ['**/node_modules/**'],
@@ -151,7 +158,7 @@ let src = await assetServer.getHref('app/assets/entry.tsx')
151
158
 
152
159
  ## Preloads
153
160
 
154
- Use `assetServer.getPreloads()` when rendering HTML so you can turn the returned URLs into `<link rel="modulepreload">` tags or `Link` headers for one or more assets and their dependencies. You can provide root-relative or absolute file paths, or `file://` URLs.
161
+ 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.
155
162
 
156
163
  ```ts
157
164
  let preloads = await assetServer.getPreloads(['app/assets/entry.tsx', 'app/assets/search.tsx'])
@@ -159,22 +166,23 @@ let preloads = await assetServer.getPreloads(['app/assets/entry.tsx', 'app/asset
159
166
  // '/assets/app/assets/entry.tsx',
160
167
  // '/assets/app/assets/search.tsx',
161
168
  // '/assets/app/assets/utils.ts',
162
- // '/assets/npm/@remix-run/component/index.js',
169
+ // '/assets/npm/@remix-run/ui/index.js',
163
170
  // ...etc
164
171
  // ]
165
172
  ```
166
173
 
167
174
  ## Fingerprinting
168
175
 
169
- By default, scripts are served at stable URLs with ETags and `Cache-Control: no-cache`. Responses are cached for the lifetime of the asset server instance.
176
+ By default, assets are served at stable URLs with ETags and `Cache-Control: no-cache`. Responses are cached for the lifetime of the asset server instance.
170
177
 
171
- If you want clients to cache scripts aggressively without revalidation, you can opt into source-based fingerprinting.
178
+ If you want clients to cache assets aggressively without revalidation, you can opt into source-based fingerprinting.
172
179
 
173
180
  ```ts
174
181
  import { createAssetServer } from 'remix/assets'
175
182
 
176
183
  let assetServer = createAssetServer({
177
- fileMap: { '/assets/app/*path': 'app/*path' },
184
+ basePath: '/assets',
185
+ fileMap: { '/app/*path': 'app/*path' },
178
186
  allow: ['app/assets/**'],
179
187
  watch: false,
180
188
  fingerprint: {
@@ -183,98 +191,98 @@ let assetServer = createAssetServer({
183
191
  })
184
192
  ```
185
193
 
186
- When fingerprinting is enabled, scripts use a `.@<fingerprint>` segment before the file extension and are served with `Cache-Control: public, max-age=31536000, immutable`.
194
+ When fingerprinting is enabled, assets use a `.@<fingerprint>` segment before the file extension and are served with `Cache-Control: public, max-age=31536000, immutable`.
187
195
 
188
- Source fingerprints are based on the original file contents and the build ID. The build ID must change for each deployment so that fingerprinted modules are invalidated together. This fingerprinting strategy assumes that files on disk won't change, so fingerprinting requires `watch: false`.
196
+ Source fingerprints are based on the original file contents and the build ID. The build ID must change for each deployment so that fingerprinted assets are invalidated together. This fingerprinting strategy assumes that files on disk won't change, so fingerprinting requires `watch: false`.
189
197
 
190
- ## Script Options
191
-
192
- ### Minification
198
+ ## Target
193
199
 
194
- Enable minification with `scripts.minify`:
200
+ Use `target` to lower emitted syntax to a specific browser support policy and/or ECMAScript version.
195
201
 
196
202
  ```ts
197
203
  import { createAssetServer } from 'remix/assets'
198
204
 
199
205
  let assetServer = createAssetServer({
200
- fileMap: { '/assets/app/*path': 'app/*path' },
206
+ basePath: '/assets',
207
+ fileMap: { '/app/*path': 'app/*path' },
201
208
  allow: ['app/assets/**'],
202
- scripts: {
203
- minify: true,
209
+ target: {
210
+ chrome: '109',
211
+ ios: '15.6',
212
+ es: '2020',
204
213
  },
205
214
  })
206
215
  ```
207
216
 
208
- ### Target
217
+ Supported target options are `chrome`, `firefox`, `safari`, `edge`, `opera`, `ios`, `samsung`, and `es` (ECMAScript version).
218
+
219
+ ### Source Maps
209
220
 
210
- Use `scripts.target` to lower emitted syntax to a specific ECMAScript version.
221
+ Enable sourcemaps with either `'external'` or `'inline'` using `sourceMaps`:
211
222
 
212
223
  ```ts
213
224
  import { createAssetServer } from 'remix/assets'
214
225
 
215
226
  let assetServer = createAssetServer({
216
- fileMap: { '/assets/app/*path': 'app/*path' },
227
+ basePath: '/assets',
228
+ fileMap: { '/app/*path': 'app/*path' },
217
229
  allow: ['app/assets/**'],
218
- scripts: {
219
- target: 'es2019',
220
- },
230
+ sourceMaps: 'external',
221
231
  })
222
232
  ```
223
233
 
224
- The default target is `esnext`, which means all syntax is preserved.
225
-
226
- ### Define
227
-
228
- Use `scripts.define` to replace global identifiers with constant expressions.
234
+ By default, sourcemap `sources` use URLs so they're presented alongside the compiled output in your browser's developer tools. You can also use file system paths instead with `sourceMapSourcePaths`:
229
235
 
230
236
  ```ts
231
237
  import { createAssetServer } from 'remix/assets'
232
238
 
233
239
  let assetServer = createAssetServer({
234
- fileMap: { '/assets/app/*path': 'app/*path' },
235
- allow: ['app/assets/**', 'app/node_modules/**'],
236
- scripts: {
237
- define: {
238
- 'process.env.NODE_ENV': '"production"',
239
- },
240
- minify: true,
241
- },
240
+ basePath: '/assets',
241
+ fileMap: { '/app/*path': 'app/*path' },
242
+ allow: ['app/assets/**'],
243
+ sourceMaps: 'inline',
244
+ sourceMapSourcePaths: 'absolute',
242
245
  })
243
246
  ```
244
247
 
245
- Values are injected exactly as defined, so string literals must include their own quotes, e.g. `process.env.NODE_ENV` must be `"production"` rather than `production`.
246
-
247
- ### Source Maps
248
+ ### Minification
248
249
 
249
- Enable sourcemaps with either `'external'` or `'inline'` using `scripts.sourceMaps`:
250
+ Enable minification with `minify`:
250
251
 
251
252
  ```ts
252
253
  import { createAssetServer } from 'remix/assets'
253
254
 
254
255
  let assetServer = createAssetServer({
255
- fileMap: { '/assets/app/*path': 'app/*path' },
256
+ basePath: '/assets',
257
+ fileMap: { '/app/*path': 'app/*path' },
256
258
  allow: ['app/assets/**'],
257
- scripts: {
258
- sourceMaps: 'external',
259
- },
259
+ minify: true,
260
260
  })
261
261
  ```
262
262
 
263
- By default, sourcemap `sources` use URLs so they're presented alongside the compiled output in your browser's developer tools. You can also use file system paths instead with `scripts.sourceMapSourcePaths`:
263
+ ## Script Options
264
+
265
+ ### Define
266
+
267
+ Use `scripts.define` to replace global identifiers with constant expressions.
264
268
 
265
269
  ```ts
266
270
  import { createAssetServer } from 'remix/assets'
267
271
 
268
272
  let assetServer = createAssetServer({
269
- fileMap: { '/assets/app/*path': 'app/*path' },
270
- allow: ['app/assets/**'],
273
+ basePath: '/assets',
274
+ fileMap: { '/app/*path': 'app/*path' },
275
+ allow: ['app/assets/**', 'app/node_modules/**'],
271
276
  scripts: {
272
- sourceMaps: 'inline',
273
- sourceMapSourcePaths: 'absolute',
277
+ define: {
278
+ 'process.env.NODE_ENV': '"production"',
279
+ },
274
280
  },
275
281
  })
276
282
  ```
277
283
 
284
+ Values are injected exactly as defined, so string literals must include their own quotes, e.g. `process.env.NODE_ENV` must be `"production"` rather than `production`.
285
+
278
286
  ### External Imports
279
287
 
280
288
  Use `scripts.external` to leave specific import specifiers unchanged by providing an array of specifiers.
@@ -283,7 +291,8 @@ Use `scripts.external` to leave specific import specifiers unchanged by providin
283
291
  import { createAssetServer } from 'remix/assets'
284
292
 
285
293
  let assetServer = createAssetServer({
286
- fileMap: { '/assets/app/*path': 'app/*path' },
294
+ basePath: '/assets',
295
+ fileMap: { '/app/*path': 'app/*path' },
287
296
  allow: ['app/assets/**'],
288
297
  scripts: {
289
298
  external: ['my-external-import'],
@@ -291,6 +300,17 @@ let assetServer = createAssetServer({
291
300
  })
292
301
  ```
293
302
 
303
+ ## CSS Imports
304
+
305
+ Relative CSS `@import` rules are rewritten to asset server URLs. External `@import` URLs are left unchanged automatically. `url()` references are preserved as authored.
306
+
307
+ ```css
308
+ /* Rewritten to asset server URL: */
309
+ @import './reset.css';
310
+ /* External URL: */
311
+ @import 'https://fonts.googleapis.com/css2?family=Inter';
312
+ ```
313
+
294
314
  ## Error Handling
295
315
 
296
316
  Use `onError` to report unexpected compilation failures and/or return a custom response.
@@ -299,11 +319,12 @@ Use `onError` to report unexpected compilation failures and/or return a custom r
299
319
  import { createAssetServer } from 'remix/assets'
300
320
 
301
321
  let assetServer = createAssetServer({
302
- fileMap: { '/assets/app/*path': 'app/*path' },
322
+ basePath: '/assets',
323
+ fileMap: { '/app/*path': 'app/*path' },
303
324
  allow: ['app/assets/**'],
304
325
  onError(error) {
305
- console.error('Failed to build client module', error)
306
- return new Response('Client module build failed', { status: 500 })
326
+ console.error('Failed to build client assets', error)
327
+ return new Response('Client asset build failed', { status: 500 })
307
328
  },
308
329
  })
309
330
  ```
@@ -1 +1 @@
1
- {"version":3,"file":"access.d.ts","sourceRoot":"","sources":["../../src/lib/access.ts"],"names":[],"mappings":"AAEA,KAAK,YAAY,GAAG;IAClB,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAA;CACrC,CAAA;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE;IAC1C,KAAK,EAAE,SAAS,MAAM,EAAE,CAAA;IACxB,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IACxB,OAAO,EAAE,MAAM,CAAA;CAChB,GAAG,YAAY,CAaf"}
1
+ {"version":3,"file":"access.d.ts","sourceRoot":"","sources":["../../src/lib/access.ts"],"names":[],"mappings":"AAGA,KAAK,YAAY,GAAG;IAClB,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAA;CACrC,CAAA;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE;IAC1C,KAAK,EAAE,SAAS,MAAM,EAAE,CAAA;IACxB,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IACxB,OAAO,EAAE,MAAM,CAAA;CAChB,GAAG,YAAY,CAcf"}
@@ -1,9 +1,12 @@
1
1
  import { createFileMatcher } from "./file-matcher.js";
2
+ import { isInjectedPackageFilePath } from "./injected-packages.js";
2
3
  export function createAccessPolicy(options) {
3
4
  let allowMatchers = options.allow.map((pattern) => createFileMatcher(pattern, options.rootDir));
4
5
  let denyMatchers = (options.deny ?? []).map((pattern) => createFileMatcher(pattern, options.rootDir));
5
6
  return {
6
7
  isAllowed(filePath) {
8
+ if (isInjectedPackageFilePath(filePath))
9
+ return true;
7
10
  if (!allowMatchers.some((matcher) => matcher(filePath)))
8
11
  return false;
9
12
  if (denyMatchers.length > 0 && denyMatchers.some((matcher) => matcher(filePath)))
@@ -1,3 +1,4 @@
1
+ import type { AssetTarget } from './target.ts';
1
2
  import type { ChokidarWatcher } from './watch.ts';
2
3
  interface AssetServerWatchOptions {
3
4
  /**
@@ -16,15 +17,26 @@ interface AssetServerWatchOptions {
16
17
  }
17
18
  interface FingerprintOptions {
18
19
  /**
19
- * Per-build invalidation token that must change whenever fingerprinted module URLs
20
+ * Per-build invalidation token that must change whenever fingerprinted asset URLs
20
21
  * should be invalidated together.
21
22
  */
22
23
  buildId: string;
23
24
  }
24
- declare const scriptTargets: readonly ["es2015", "es2016", "es2017", "es2018", "es2019", "es2020", "es2021", "es2022", "es2023", "es2024", "es2025", "es2026", "esnext"];
25
- export type ScriptsTarget = (typeof scriptTargets)[number];
25
+ type AssetSourceMaps = 'inline' | 'external';
26
+ type AssetSourceMapSourcePaths = 'url' | 'absolute';
27
+ interface AssetServerScriptOptions {
28
+ /**
29
+ * Replace global expressions with constant values during transform, e.g.
30
+ * `{ 'process.env.NODE_ENV': '"production"' }`
31
+ */
32
+ define?: Record<string, string>;
33
+ /** Import specifiers to leave unrewritten (CDN URLs, import map entries, etc.) */
34
+ external?: string[];
35
+ }
26
36
  export interface AssetServerOptions {
27
- /** File patterns keyed by public URL patterns. */
37
+ /** Public mount path for this asset server, e.g. `'/assets'`. */
38
+ basePath: string;
39
+ /** File patterns keyed by public URL patterns relative to `basePath`. */
28
40
  fileMap: Readonly<Record<string, string>>;
29
41
  /**
30
42
  * Root directory used to resolve relative file paths. Defaults to `process.cwd()`.
@@ -39,45 +51,37 @@ export interface AssetServerOptions {
39
51
  */
40
52
  deny?: readonly string[];
41
53
  /**
42
- * Controls optional source-based URL fingerprinting for rewritten import URLs.
54
+ * Controls optional source-based URL fingerprinting for rewritten asset URLs.
43
55
  *
44
- * When omitted, all served modules use stable non-fingerprinted URLs with `Cache-Control: no-cache`.
56
+ * When omitted, all served assets use stable non-fingerprinted URLs with `Cache-Control: no-cache`.
45
57
  * Cannot be used together with active watch mode. Set `watch: false` when fingerprinting.
46
58
  */
47
59
  fingerprint?: FingerprintOptions;
48
60
  /**
49
- * Script pipeline configuration. Omit to use defaults.
50
- */
51
- scripts?: {
52
- /**
53
- * Source map mode (disabled when omitted).
54
- * - `'external'`: serve source maps as separate `.map` files; adds `//# sourceMappingURL=` comment
55
- * - `'inline'`: embed source maps as a base64 data URL directly in the JS; no separate `.map` file
56
- */
57
- sourceMaps?: 'inline' | 'external';
58
- /**
59
- * Controls the source paths written into source map `sources`.
60
- * - `'url'` (default): use the stable server path (e.g. `'/assets/app/entry.ts'`)
61
- * - `'absolute'`: use the original filesystem path on disk
62
- */
63
- sourceMapSourcePaths?: 'url' | 'absolute';
64
- /**
65
- * Minify emitted modules.
66
- */
67
- minify?: boolean;
68
- /**
69
- * Replace global expressions with constant values during transform, e.g.
70
- * `{ 'process.env.NODE_ENV': '"production"' }`
71
- */
72
- define?: Record<string, string>;
73
- /**
74
- * Lower emitted syntax to a specific ECMAScript target. Omit this option to preserve
75
- * modern syntax unless project configuration already requests a lower target.
76
- */
77
- target?: ScriptsTarget;
78
- /** Import specifiers to leave unrewritten (CDN URLs, import map entries, etc.) */
79
- external?: string[];
80
- };
61
+ * Shared compatibility target for scripts and styles. Browser targets apply to both
62
+ * pipelines, and `es` only affects scripts.
63
+ */
64
+ target?: AssetTarget;
65
+ /**
66
+ * Source map mode for scripts and styles.
67
+ * - `'external'`: serve source maps as separate `.map` files
68
+ * - `'inline'`: embed source maps as a base64 data URL in the compiled asset
69
+ */
70
+ sourceMaps?: AssetSourceMaps;
71
+ /**
72
+ * Source path strategy for source map `sources`.
73
+ * - `'url'` (default): use the stable server path (e.g. `'/assets/app/entry.ts'`)
74
+ * - `'absolute'`: use the original filesystem path on disk
75
+ */
76
+ sourceMapSourcePaths?: AssetSourceMapSourcePaths;
77
+ /**
78
+ * Minification setting for emitted scripts and styles.
79
+ */
80
+ minify?: boolean;
81
+ /**
82
+ * Script-only configuration.
83
+ */
84
+ scripts?: AssetServerScriptOptions;
81
85
  /**
82
86
  * Enable filesystem-backed cache invalidation for long-lived server instances.
83
87
  * Enabled by default. Pass `true` to use the default watcher options, an options
@@ -92,16 +96,16 @@ export interface AssetServerOptions {
92
96
  }
93
97
  export interface AssetServer {
94
98
  /**
95
- * Serves a script request. Returns `Response | null` — null means the request was not
96
- * handled by this server, letting the router fall through to a 404.
99
+ * Serves a script or style request. Returns `Response | null` — null means the request
100
+ * was not handled by this server, letting the router fall through to a 404.
97
101
  */
98
102
  fetch(request: Request): Promise<Response | null>;
99
103
  /**
100
- * Returns the request href for a served module file.
104
+ * Returns the request href for a served asset file.
101
105
  */
102
106
  getHref(filePath: string): Promise<string>;
103
107
  /**
104
- * Returns preload URLs for one or more served module files, ordered shallowest-first.
108
+ * Returns preload URLs for one or more served asset files, ordered shallowest-first.
105
109
  */
106
110
  getPreloads(filePath: string | readonly string[]): Promise<string[]>;
107
111
  /**
@@ -114,8 +118,8 @@ export declare function getInternalWatchTargets(assetServer: AssetServer): reado
114
118
  /**
115
119
  * Create an asset server instance
116
120
  *
117
- * Compiles TypeScript/JavaScript modules on demand with optional source-based URL
118
- * fingerprinting, caching, and configurable file mapping.
121
+ * Compiles TypeScript/JavaScript scripts and CSS styles on demand with optional
122
+ * source-based URL fingerprinting, caching, and configurable file mapping.
119
123
  *
120
124
  * @param options Server configuration
121
125
  * @returns A {@link AssetServer} with `fetch()`, `getHref()`, and `getPreloads()` methods
@@ -123,8 +127,9 @@ export declare function getInternalWatchTargets(assetServer: AssetServer): reado
123
127
  * @example
124
128
  * ```ts
125
129
  * let assetServer = createAssetServer({
130
+ * basePath: '/assets',
126
131
  * fileMap: {
127
- * '/assets/app/*path': 'app/*path',
132
+ * '/app/*path': 'app/*path',
128
133
  * },
129
134
  * allow: ['app/**'],
130
135
  * })
@@ -1 +1 @@
1
- {"version":3,"file":"asset-server.d.ts","sourceRoot":"","sources":["../../src/lib/asset-server.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAGjD,UAAU,uBAAuB;IAC/B;;;OAGG;IACH,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IAC1B;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAA;IACd;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;AAED,UAAU,kBAAkB;IAC1B;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,QAAA,MAAM,aAAa,6IAcT,CAAA;AAGV,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAA;AAE1D,MAAM,WAAW,kBAAkB;IACjC,kDAAkD;IAClD,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;IACzC;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;OAEG;IACH,KAAK,EAAE,SA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