@normed/bundle 4.7.1 → 4.8.2

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/CHANGELOG.md CHANGED
@@ -6,6 +6,10 @@ Given a version number MAJOR.MINOR.PATCH, increment the:
6
6
  2. MINOR version when you add functionality in a backwards compatible manner, and
7
7
  3. PATCH version when you make backwards compatible bug fixes.
8
8
 
9
+ # 4.8.0
10
+
11
+ * MINOR: Add `webRoot` config for correct asset URL resolution when the web root is a subdirectory of `outdir`. Asset URLs in HTML are computed relative to the web root instead of the output directory. Also promotes `publicPath` and `assetNames` to top-level `bundle` config (old nested location still works but logs a deprecation warning).
12
+
9
13
  # 4.7.1
10
14
 
11
15
  * PATCH: Fix `node.attrs is not iterable` error in pug templates when non-Tag AST nodes (e.g. code blocks, mixins, comments) are encountered during asset path rebasing.
package/README.md CHANGED
@@ -194,50 +194,64 @@ This means these files referenced from your CSS/JS will be copied to the output
194
194
 
195
195
  ### asset paths
196
196
 
197
- By default, asset paths in the output are relative to the HTML/CSS file that references them. To serve static assets (images, fonts, media files) from a CDN or a specific URL prefix, use the `publicPath` esbuild option:
197
+ Control how static assets (images, fonts, media) are named and referenced in your output.
198
198
 
199
199
  ```json
200
200
  {
201
201
  "bundle": {
202
- "baseConfig": {
203
- "javascript": {
204
- "esbuild": {
205
- "publicPath": "https://cdn.example.com/assets"
206
- }
207
- }
208
- }
202
+ "assetNames": "assets/[name]-[hash]",
203
+ "publicPath": "https://cdn.example.com"
209
204
  }
210
205
  }
211
206
  ```
212
207
 
213
- With this configuration, static asset references like `<img src="logo.png">` in pug/HTML and `url(images/bg.png)` in CSS will be rewritten to use the public path prefix (e.g., `https://cdn.example.com/assets/logo-A1B2C3D4.png`).
208
+ - **`assetNames`** Template for output filenames. Supports `[name]`, `[hash]`, `[ext]`, `[dir]`. Default: `[name]-[hash]`.
209
+ - **`publicPath`** — URL prefix prepended to asset references in HTML and CSS. Useful for CDNs or when assets are served from a specific path.
214
210
 
215
211
  **Note:** `publicPath` only affects static assets (images, fonts, media). Links between HTML pages, CSS stylesheets, and JavaScript files discovered in pug templates always use relative paths.
216
212
 
217
- You can also customize how asset filenames are generated using the `assetNames` option:
213
+ The default `assetNames` is `[name]-[hash]` for static assets in pug templates. For CSS/JS files discovered in pug templates, the default is `[dir]/[name]-[hash]` to preserve directory structure.
214
+
215
+ #### Serving from a subdirectory (`webRoot`)
216
+
217
+ If your output has a subdirectory that serves as the web root (common when bundling both server and client code), set `webRoot` so asset URLs are computed relative to it:
218
218
 
219
219
  ```json
220
220
  {
221
221
  "bundle": {
222
- "baseConfig": {
223
- "javascript": {
224
- "esbuild": {
225
- "publicPath": "/static",
226
- "assetNames": "assets/[name]-[hash]"
227
- }
228
- }
229
- }
222
+ "webRoot": "public",
223
+ "assetNames": "public/assets/[name]-[hash]"
224
+ }
225
+ }
226
+ ```
227
+
228
+ ```
229
+ src/ bundles/
230
+ ├─ public/ ├─ public/
231
+ │ ├─ index.static.pug → │ ├─ index.html
232
+ │ ├─ logo.png → │ ├─ assets/logo-A1B2C3D4.png
233
+ ├─ worker.node.ts → ├─ worker.js
234
+ ```
235
+
236
+ With `webRoot: "public"`, `index.html` references the logo as `/assets/logo-A1B2C3D4.png` — correct for a server serving `bundles/public/` at `/`.
237
+
238
+ Without `webRoot`, the reference would incorrectly be `/assets/public/assets/logo-A1B2C3D4.png`.
239
+
240
+ To host under a URL prefix, combine with `publicPath`:
241
+
242
+ ```json
243
+ {
244
+ "bundle": {
245
+ "webRoot": "public",
246
+ "publicPath": "/myapp",
247
+ "assetNames": "public/assets/[name]-[hash]"
230
248
  }
231
249
  }
232
250
  ```
233
251
 
234
- The `assetNames` template supports the following placeholders:
235
- - `[name]` - The original filename without extension
236
- - `[hash]` - A content-based hash for cache busting
237
- - `[ext]` - The file extension
238
- - `[dir]` - The directory path relative to the source directory
252
+ This produces URLs like `/myapp/assets/logo-A1B2C3D4.png`.
239
253
 
240
- The default is `[name]-[hash]` for static assets in pug templates. For CSS/JS files discovered in pug templates, the default is `[dir]/[name]-[hash]` to preserve directory structure.
254
+ > **Note:** These options can also be set under `baseConfig.javascript.esbuild` for backwards compatibility, but the top-level location is preferred.
241
255
 
242
256
  ### external CSS URLs
243
257