bun_bun_bundle 0.3.4 → 0.3.5
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.
- checksums.yaml +4 -4
- data/README.md +91 -47
- data/lib/bun/plugins/jsGlobs.js +2 -1
- data/lib/bun_bun_bundle/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1bb9590f4f3d07e85a9db1cf04c6a71e23b8a6ccb2a8b5fd64a867d5be370b17
|
|
4
|
+
data.tar.gz: b9afcef3823bebe8b7042aaf23bc395dc9c5ce1594cfae40826f8b038fba8af1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6727eabdfe950a26ab037110a7ff68251cf7f7c15c2b7d867c944c5386ddd6b38b5d571f80ee747add1f7cb957aebc1b6f940124cf9a02fce88fb225d75785cc
|
|
7
|
+
data.tar.gz: edf32a9181f1f26fb0bbdf05eb9a5f604d2900cd232c0f450d3688e60da030a3d8008f22b7528bae848157fb93749f3e9ace937bc5c925ab170c1b2ee016020e
|
data/README.md
CHANGED
|
@@ -7,39 +7,17 @@ Works with Rails, Hanami, or any Rack app.
|
|
|
7
7
|
|
|
8
8
|
## Why use BunBunBundle?
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
### Asset fingerprinting
|
|
23
|
-
|
|
24
|
-
Every asset is fingerprinted with a content-based hash in production, so
|
|
25
|
-
browsers always fetch the right version.
|
|
26
|
-
|
|
27
|
-
### No surprises in production
|
|
28
|
-
|
|
29
|
-
Development and production builds go through the exact same pipeline. The only
|
|
30
|
-
differences are fingerprinting and minification being enabled in production,
|
|
31
|
-
but nothing is holding you back from enabling them in development as well.
|
|
32
|
-
|
|
33
|
-
### Extensible plugin system
|
|
34
|
-
|
|
35
|
-
BunBunBundle comes with built-in plugins for root aliases, CSS glob imports,
|
|
36
|
-
and JS glob imports. Plugins are simple, plain JS files, so you can create your
|
|
37
|
-
own JS/CSS transformers, and raw Bun plugins are supported as well.
|
|
38
|
-
|
|
39
|
-
### Just one dependency: Bun
|
|
40
|
-
|
|
41
|
-
The bundler ships with the gem. Bun is the only external requirement, so other
|
|
42
|
-
than that, there are no dev dependencies.
|
|
10
|
+
- **Lightning fast.** Bun's native bundler builds assets in milliseconds.
|
|
11
|
+
- **CSS hot-reloading.** Instant changes without a full page refresh.
|
|
12
|
+
- **Asset fingerprinting.** Fast, content-based file hashing.
|
|
13
|
+
- **No surprises in production.** Dev and prod go through the same pipeline.
|
|
14
|
+
- **Extensible.** Plugins are simple, tiny JavaScript files.
|
|
15
|
+
- **One dependency: Bun.** Everything is included, no other dev dependencies.
|
|
16
|
+
|
|
17
|
+
> [!Note]
|
|
18
|
+
> The original repository is hosted at
|
|
19
|
+
> [Codeberg](https://codeberg.org/w0u7/bun_bun_bundle). The [GitHub
|
|
20
|
+
> repo](https://github.com/wout/bun_bun_bundle) is just a mirror.
|
|
43
21
|
|
|
44
22
|
## Installation
|
|
45
23
|
|
|
@@ -79,17 +57,18 @@ your views immediately:
|
|
|
79
57
|
<html>
|
|
80
58
|
<head>
|
|
81
59
|
<%= bun_css_tag('css/app.css') %>
|
|
60
|
+
<%= bun_js_tag('js/app.js', defer: true) %>
|
|
61
|
+
<%= bun_reload_tag %>
|
|
82
62
|
</head>
|
|
83
63
|
<body>
|
|
84
64
|
<%= bun_img_tag('images/logo.png', alt: 'My App') %>
|
|
85
|
-
<%= bun_js_tag('js/app.js', defer: true) %>
|
|
86
|
-
<%= bun_reload_tag %>
|
|
87
65
|
</body>
|
|
88
66
|
</html>
|
|
89
67
|
```
|
|
90
68
|
|
|
91
|
-
|
|
92
|
-
|
|
69
|
+
> [!NOTE]
|
|
70
|
+
> The `DevCacheMiddleware` is automatically inserted in development to prevent
|
|
71
|
+
> stale asset caching.
|
|
93
72
|
|
|
94
73
|
## Usage with Hanami
|
|
95
74
|
|
|
@@ -97,7 +76,8 @@ Hanami ships with its own esbuild-based asset pipeline. Since BunBunBundle
|
|
|
97
76
|
replaces it entirely, you can clean up the default setup:
|
|
98
77
|
|
|
99
78
|
- Remove `gem 'hanami-assets'` from your `Gemfile`
|
|
100
|
-
- Delete `config/assets.js
|
|
79
|
+
- Delete `config/assets.js`
|
|
80
|
+
- Remove all dev dependencies from `package.json`
|
|
101
81
|
|
|
102
82
|
1. Set up the Hanami integration:
|
|
103
83
|
|
|
@@ -280,8 +260,8 @@ example:
|
|
|
280
260
|
import _glob_components_theme from './components/theme.js'
|
|
281
261
|
import _glob_components_shared_tooltip from './components/shared/tooltip.js'
|
|
282
262
|
const components = {
|
|
283
|
-
'
|
|
284
|
-
'
|
|
263
|
+
'theme': _glob_components_theme,
|
|
264
|
+
'shared/tooltip': _glob_components_shared_tooltip
|
|
285
265
|
}
|
|
286
266
|
```
|
|
287
267
|
|
|
@@ -291,15 +271,26 @@ const components = {
|
|
|
291
271
|
### Custom plugins
|
|
292
272
|
|
|
293
273
|
Custom plugins are JS files referenced by their path in the config. Each file
|
|
294
|
-
must export a factory function that receives a context object
|
|
295
|
-
|
|
296
|
-
|
|
274
|
+
must export a factory function that receives a context object. What the factory
|
|
275
|
+
returns determines the plugin type.
|
|
276
|
+
|
|
277
|
+
The context object has the following properties:
|
|
278
|
+
|
|
279
|
+
| Property | Description |
|
|
280
|
+
| ---------- | -------------------------------------------- |
|
|
281
|
+
| `root` | Absolute path to the project root |
|
|
282
|
+
| `config` | The resolved `bun.json` configuration object |
|
|
283
|
+
| `dev` | `true` when running in development mode |
|
|
284
|
+
| `prod` | `true` when running in production mode |
|
|
285
|
+
| `manifest` | The current asset manifest object |
|
|
297
286
|
|
|
298
287
|
#### Simple transform plugins
|
|
299
288
|
|
|
300
289
|
A simple transform plugin returns a function that receives the file content as
|
|
301
|
-
a string and an `args` object
|
|
302
|
-
|
|
290
|
+
a string and an `args` object from Bun's
|
|
291
|
+
[`onLoad`](https://bun.sh/docs/bundler/plugins#onload) hook (containing `path`,
|
|
292
|
+
`loader`, etc.). It should return the transformed content. The transform can be
|
|
293
|
+
synchronous or asynchronous.
|
|
303
294
|
|
|
304
295
|
Transforms are chained in the order they appear in the config, so each
|
|
305
296
|
transform receives the output of the previous one.
|
|
@@ -308,8 +299,8 @@ transform receives the output of the previous one.
|
|
|
308
299
|
// config/bun/banner.js
|
|
309
300
|
|
|
310
301
|
export default function banner({prod}) {
|
|
311
|
-
return content => {
|
|
312
|
-
const stamp = prod ? '' : ` (dev
|
|
302
|
+
return (content, args) => {
|
|
303
|
+
const stamp = prod ? '' : ` (dev ${args.path})`
|
|
313
304
|
return `/* My App${stamp} */\n${content}`
|
|
314
305
|
}
|
|
315
306
|
}
|
|
@@ -354,6 +345,11 @@ Reference custom plugins by their file path in your config:
|
|
|
354
345
|
}
|
|
355
346
|
```
|
|
356
347
|
|
|
348
|
+
> [!WARNING]
|
|
349
|
+
> The order of the plugins matters here. For example, the aliases plugin needs
|
|
350
|
+
> to resolve the paths first before the glob plugin can do its work. Keep that
|
|
351
|
+
> in mind for your own plugins too.
|
|
352
|
+
|
|
357
353
|
## Project structure
|
|
358
354
|
|
|
359
355
|
```
|
|
@@ -373,6 +369,25 @@ your-app/
|
|
|
373
369
|
└── bun-manifest.json # Asset manifest (generated)
|
|
374
370
|
```
|
|
375
371
|
|
|
372
|
+
## Deploying with Docker
|
|
373
|
+
|
|
374
|
+
Install Bun, your JS dependencies, then run the build step:
|
|
375
|
+
|
|
376
|
+
```dockerfile
|
|
377
|
+
RUN curl -fsSL https://bun.sh/install | bash
|
|
378
|
+
ENV PATH="/root/.bun/bin:${PATH}"
|
|
379
|
+
|
|
380
|
+
COPY package.json bun.lock ./
|
|
381
|
+
RUN bun install --frozen-lockfile
|
|
382
|
+
|
|
383
|
+
COPY . .
|
|
384
|
+
RUN bundle exec bun_bun_bundle build
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
> [!NOTE]
|
|
388
|
+
> If you're using BunBunBundle in Rails as your only asset pipeline, you can
|
|
389
|
+
> skip the `rails assets:precompile` step entirely.
|
|
390
|
+
|
|
376
391
|
## Origins
|
|
377
392
|
|
|
378
393
|
BunBunBundle was originally built for [Fluck](https://fluck.site), a
|
|
@@ -397,8 +412,37 @@ well. I hope you enjoy it too!
|
|
|
397
412
|
|
|
398
413
|
## Contributing
|
|
399
414
|
|
|
415
|
+
### Setup
|
|
416
|
+
|
|
417
|
+
```sh
|
|
418
|
+
git clone https://codeberg.org/w0u7/bun_bun_bundle.git
|
|
419
|
+
cd bun_bun_bundle
|
|
420
|
+
bundle install
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
### Running tests
|
|
424
|
+
|
|
425
|
+
```sh
|
|
426
|
+
bundle exec rake test # run all tests
|
|
427
|
+
bundle exec rake test:ruby # Ruby tests only (Minitest, in spec/)
|
|
428
|
+
bundle exec rake test:bun # JS tests only (Bun, plugin tests)
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
> [!NOTE]
|
|
432
|
+
> `bundle exec rake` with no arguments runs all tests too.
|
|
433
|
+
|
|
434
|
+
### Linting
|
|
435
|
+
|
|
436
|
+
```sh
|
|
437
|
+
bundle exec rubocop
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
### Commit conventions
|
|
441
|
+
|
|
400
442
|
We use [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/).
|
|
401
443
|
|
|
444
|
+
### Submitting changes
|
|
445
|
+
|
|
402
446
|
1. Fork it
|
|
403
447
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
404
448
|
3. Commit your changes (`git commit -am 'feat: new feature'`)
|
data/lib/bun/plugins/jsGlobs.js
CHANGED
|
@@ -34,7 +34,8 @@ export default function jsGlobs() {
|
|
|
34
34
|
const ext = extname(file)
|
|
35
35
|
const relative = baseDir ? file.slice(baseDir.length + 1) : file
|
|
36
36
|
const key = relative.slice(0, -ext.length)
|
|
37
|
-
const
|
|
37
|
+
const prefix = baseDir ? `${baseDir}_` : ''
|
|
38
|
+
const safe = `_glob_${prefix}${key}`.replace(/[^a-zA-Z0-9]/g, '_')
|
|
38
39
|
imports.push(`import ${safe} from './${file}'`)
|
|
39
40
|
entries.push(` '${key}': ${safe}`)
|
|
40
41
|
}
|