@normed/bundle 4.3.2 → 4.5.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/CHANGELOG.md CHANGED
@@ -6,6 +6,19 @@ 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.5.0
10
+
11
+ * MINOR: Adds asset processing for pug entrypoints. Images, fonts, and other assets referenced in pug files are now hashed, copied to the output directory, and their paths rewritten automatically.
12
+ * MINOR: Adds automatic pug-to-pug entrypoint discovery. When a pug file links to another pug file (e.g., `a(href="about.pug")`), the linked file is automatically built as an entrypoint and the href is rewritten to point to the output path.
13
+
14
+ # 4.4.0
15
+
16
+ * MINOR: Adds `css.externalUrls` configuration option for marking URL patterns as external in CSS files.
17
+ * MINOR: Adds `createCssExternalUrlsPlugin` esbuild plugin.
18
+ * MINOR: Adds the `asset` modifier for copying files verbatim without processing.
19
+ * MINOR: Adds default file loaders for common asset types (images, fonts, media).
20
+ * PATCH: Adds documentation for common pitfalls.
21
+
9
22
  # 4.3.2
10
23
 
11
24
  * MINOR: fixes map files being expected when no sourcemap value is set.
package/README.md CHANGED
@@ -83,6 +83,13 @@ type EntryConfig = {
83
83
  "config"?: string | ESBuildConfig,
84
84
  }
85
85
  }
86
+
87
+ // Configuration specific to CSS processing
88
+ "css"?: {
89
+ // URL patterns to mark as external (not resolved at build time)
90
+ // Supports glob-style wildcards, e.g. ["/fonts/*", "/images/*"]
91
+ "externalUrls"?: string[]
92
+ }
86
93
  }
87
94
  ```
88
95
 
@@ -160,6 +167,79 @@ Any files you don't want to name with such a suffix can be added manually. To ad
160
167
  yarn bundle --entrypoint anchovies.ts --entrypoint pics/cartoons.png
161
168
  ```
162
169
 
170
+ ### asset modifier
171
+
172
+ Use the `.asset` modifier to copy files verbatim without any processing. This is useful for pre-built CSS or JavaScript files that should not be processed by esbuild:
173
+
174
+ ```
175
+ src/
176
+ ├─ vendor/
177
+ │ ├─ legacy.asset.js → bundles/vendor/legacy.js (copied verbatim)
178
+ │ ├─ styles.asset.css → bundles/vendor/styles.css (copied verbatim)
179
+ ```
180
+
181
+ This is particularly helpful for:
182
+ - Third-party CSS/JS libraries with complex `url()` references
183
+ - Pre-minified vendor files
184
+ - Files with runtime paths that shouldn't be resolved at build time
185
+
186
+ ### default file loaders
187
+
188
+ Common asset types are automatically configured to use esbuild's `file` loader:
189
+ - Images: `.png`, `.jpg`, `.jpeg`, `.gif`, `.webp`, `.svg`, `.ico`
190
+ - Fonts: `.ttf`, `.otf`, `.woff`, `.woff2`, `.eot`
191
+ - Media: `.mp4`, `.webm`, `.mp3`, `.wav`
192
+
193
+ This means these files referenced from your CSS/JS will be copied to the output directory and their paths will be rewritten appropriately.
194
+
195
+ ### external CSS URLs
196
+
197
+ For CSS files that reference runtime paths (like `/fonts/*` or `/images/*`) that should not be resolved at build time, use the `css.externalUrls` configuration:
198
+
199
+ ```json
200
+ {
201
+ "bundle": {
202
+ "baseConfig": {
203
+ "css": {
204
+ "externalUrls": ["/fonts/*", "/images/*", "https://*"]
205
+ }
206
+ }
207
+ }
208
+ }
209
+ ```
210
+
211
+ URL patterns support glob-style wildcards (`*`). URLs matching these patterns will be marked as external and left unchanged in the output CSS.
212
+
213
+ ### pug-to-pug linking
214
+
215
+ When a pug file contains links to other pug files, those linked files are automatically discovered and built as entrypoints. The href attributes are rewritten to point to the compiled HTML output.
216
+
217
+ ```pug
218
+ //- index.static.pug
219
+ html
220
+ body
221
+ nav
222
+ a(href="about.pug") About Us
223
+ a(href="pages/contact.pug") Contact
224
+ ```
225
+
226
+ This produces:
227
+ ```
228
+ src/ bundles/
229
+ ├─ index.static.pug → ├─ index.html (href rewritten to "about.html")
230
+ ├─ about.pug → ├─ about.html (auto-discovered)
231
+ ├─ pages/ ├─ pages/
232
+ └─ contact.pug → └─ contact.html (auto-discovered)
233
+ ```
234
+
235
+ Features:
236
+ - **Recursive**: If `about.pug` links to `team.pug`, that gets built too
237
+ - **Circular reference safe**: Files are only processed once
238
+ - **Asset handling**: Images and other assets in discovered pug files are processed normally
239
+ - **Warning on missing**: A warning is logged if a referenced pug file doesn't exist
240
+
241
+ This works for all HTML attributes that can contain paths (href, src, data, poster, etc.).
242
+
163
243
  ### analyse
164
244
 
165
245
  To get a report on bundle content and size enable analysis:
@@ -246,6 +326,44 @@ import { verifyBuilder } from '@normed/bundle';
246
326
 
247
327
  This does not fully test your builder, but it does run some tests we have found helpful.
248
328
 
329
+ # Common Pitfalls
330
+
331
+ ### Custom entrypoint modifiers not discovered
332
+
333
+ **Problem**: You want to use a custom file suffix like `.worker.ts` but files aren't being discovered.
334
+
335
+ **Cause**: Using `platformModifiers` in package.json. This is a CLI-only option, not a package.json config.
336
+
337
+ **Solution**: Use `modifiers` with `entrypoint: true`:
338
+
339
+ ```json
340
+ {
341
+ "bundle": {
342
+ "modifiers": {
343
+ "worker": {
344
+ "entrypoint": true,
345
+ "extends": "server"
346
+ }
347
+ }
348
+ }
349
+ }
350
+ ```
351
+
352
+ Now `*.worker.ts` files will be discovered and built with server platform settings.
353
+
354
+ ### No entrypoints found
355
+
356
+ **Problem**: Build completes but reports "No entrypoints".
357
+
358
+ **Cause**: Files must match a recognized pattern (`.static.*`, `.node.*`, `.web.*`, or custom modifiers with `entrypoint: true`).
359
+
360
+ **Solution**: Either:
361
+ 1. Rename your file to use a recognized pattern (e.g., `index.static.ts`)
362
+ 2. Add a custom modifier in package.json (see above)
363
+ 3. Manually specify entrypoints: `"entrypoints": ["myfile.ts"]`
364
+
365
+ Use `LOG_LEVEL=verbose yarn bundle` to see which patterns are being searched.
366
+
249
367
  # Potential errors
250
368
 
251
369
  es-build, which is essentially the basis for this whole thing, breaks reproducible builds as it includes the full path to a file as both a comment and a map key. To get around this we manually replace certain paths on build. There is a good chance this will not work for globally installed modules and will break certain hard coded strings.