bun_bun_bundle 0.6.1 → 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.
- checksums.yaml +4 -4
- data/README.md +9 -9
- data/lib/bun/bun_bundle.js +9 -3
- data/lib/bun_bun_bundle/helpers.rb +1 -0
- data/lib/bun_bun_bundle/manifest.rb +0 -4
- data/lib/bun_bun_bundle/reload_tag.rb +4 -11
- 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: 1cfd07c4a4982f58446af9f2deb5230a4225e3c733165b37038ba08fbb8bb29a
|
|
4
|
+
data.tar.gz: 6dcc33af22e42b4a6cd260185f9bae495657ed19307a8f57c3a141d58c411376
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7bea055db0ae0841a0d29fed3e785d71b9b956edcf6c37d8c5b03c340e0d29d324300439c817b29131a4978ab021b4f3686701537c7f8b371fbf578bf95bf765
|
|
7
|
+
data.tar.gz: 1fbc83c7ac9e3918e583a2ee23239006e6507f9a047234068b0e96d9995654f123291ff5359ce2b55ee7344e1ececc108c5b456e13658ddf8df4f1e1996c8a62
|
data/README.md
CHANGED
|
@@ -9,7 +9,7 @@ Works with Rails, Hanami, or any Rack app.
|
|
|
9
9
|
|
|
10
10
|
- **Lightning fast.** Bun's native bundler builds assets in milliseconds.
|
|
11
11
|
- **CSS hot-reloading.** Instant changes without a full page refresh.
|
|
12
|
-
- **Asset fingerprinting.**
|
|
12
|
+
- **Asset fingerprinting.** Content-based hashing in every environment.
|
|
13
13
|
- **No surprises in production.** Dev and prod go through the same pipeline.
|
|
14
14
|
- **Extensible.** Plugins are simple, tiny JavaScript files.
|
|
15
15
|
- **One dependency: Bun.** Everything is included, no other dev dependencies.
|
|
@@ -139,13 +139,13 @@ BunBunBundle.asset_host = 'https://cdn.example.com'
|
|
|
139
139
|
All helpers are prefixed with `bun_` to avoid conflicts with existing framework
|
|
140
140
|
helpers:
|
|
141
141
|
|
|
142
|
-
| Helper | Description
|
|
143
|
-
| -------------------------------- |
|
|
144
|
-
| `bun_asset('images/logo.png')` | Returns the fingerprinted asset path
|
|
145
|
-
| `bun_js_tag('js/app.js')` | Generates a `<script>` tag
|
|
146
|
-
| `bun_css_tag('css/app.css')` | Generates a `<link>` tag
|
|
147
|
-
| `bun_img_tag('images/logo.png')` | Generates an `<img>` tag
|
|
148
|
-
| `bun_reload_tag` | Live reload script (only renders in development)
|
|
142
|
+
| Helper | Description |
|
|
143
|
+
| -------------------------------- | ------------------------------------------------------- |
|
|
144
|
+
| `bun_asset('images/logo.png')` | Returns the fingerprinted asset path |
|
|
145
|
+
| `bun_js_tag('js/app.js')` | Generates a `<script>` tag |
|
|
146
|
+
| `bun_css_tag('css/app.css')` | Generates a `<link>` tag (with `data-bun-entry` in dev) |
|
|
147
|
+
| `bun_img_tag('images/logo.png')` | Generates an `<img>` tag |
|
|
148
|
+
| `bun_reload_tag` | Live reload script (only renders in development) |
|
|
149
149
|
|
|
150
150
|
All tag helpers accept additional HTML attributes:
|
|
151
151
|
|
|
@@ -176,7 +176,7 @@ bun_bun_bundle dev
|
|
|
176
176
|
# Build assets
|
|
177
177
|
bun_bun_bundle build
|
|
178
178
|
|
|
179
|
-
# Build with
|
|
179
|
+
# Build with minification
|
|
180
180
|
bun_bun_bundle build --prod
|
|
181
181
|
|
|
182
182
|
# Development with verbose WebSocket logging
|
data/lib/bun/bun_bundle.js
CHANGED
|
@@ -80,8 +80,6 @@ export default {
|
|
|
80
80
|
},
|
|
81
81
|
|
|
82
82
|
fingerprint(name, ext, content) {
|
|
83
|
-
if (!this.prod) return `${name}${ext}`
|
|
84
|
-
|
|
85
83
|
const hash = Bun.hash(content).toString(16).slice(0, 8)
|
|
86
84
|
return `${name}-${hash}${ext}`
|
|
87
85
|
},
|
|
@@ -211,7 +209,15 @@ export default {
|
|
|
211
209
|
|
|
212
210
|
reload(type = 'full') {
|
|
213
211
|
setTimeout(() => {
|
|
214
|
-
const
|
|
212
|
+
const payload = {type}
|
|
213
|
+
|
|
214
|
+
if (type === 'css') {
|
|
215
|
+
payload.paths = Object.values(this.manifest)
|
|
216
|
+
.filter(p => p.endsWith('.css'))
|
|
217
|
+
.map(p => `${this.config.publicPath}/${p}`)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const message = JSON.stringify(payload)
|
|
215
221
|
for (const client of this.wsClients) {
|
|
216
222
|
try {
|
|
217
223
|
client.send(message)
|
|
@@ -46,6 +46,7 @@ module BunBunBundle
|
|
|
46
46
|
def bun_css_tag(source, **options)
|
|
47
47
|
href = bun_asset(source)
|
|
48
48
|
attrs = { type: 'text/css', rel: 'stylesheet' }.merge(options).merge(href: href)
|
|
49
|
+
attrs[:data_bun_entry] = source if BunBunBundle.development?
|
|
49
50
|
bun_safe(%(<link #{bun_html_attrs(attrs)}>))
|
|
50
51
|
end
|
|
51
52
|
|
|
@@ -22,14 +22,10 @@ module BunBunBundle
|
|
|
22
22
|
return '' unless BunBunBundle.development?
|
|
23
23
|
|
|
24
24
|
config = BunBunBundle.config
|
|
25
|
-
css_paths = BunBunBundle.manifest.css_entry_points.map do |key|
|
|
26
|
-
"#{config.public_path}/#{key}"
|
|
27
|
-
end
|
|
28
25
|
|
|
29
26
|
html = <<~HTML
|
|
30
27
|
<script>
|
|
31
28
|
(() => {
|
|
32
|
-
const cssPaths = #{css_paths.to_json};
|
|
33
29
|
const ws = new WebSocket('#{config.dev_server.ws_url}')
|
|
34
30
|
let connected = false
|
|
35
31
|
|
|
@@ -37,13 +33,10 @@ module BunBunBundle
|
|
|
37
33
|
const data = JSON.parse(event.data)
|
|
38
34
|
|
|
39
35
|
if (data.type === 'css') {
|
|
40
|
-
document.querySelectorAll('link[
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
url.searchParams.set('r', Date.now())
|
|
45
|
-
link.href = url.toString()
|
|
46
|
-
}
|
|
36
|
+
document.querySelectorAll('link[data-bun-entry]').forEach(link => {
|
|
37
|
+
const entry = link.dataset.bunEntry
|
|
38
|
+
const path = data.paths.find(p => p.replace(/-[0-9a-f]{8}\\.css$/, '') === entry)
|
|
39
|
+
if (path) link.href = path
|
|
47
40
|
})
|
|
48
41
|
console.log('\\u25b8 CSS reloaded')
|
|
49
42
|
} else if (data.type === 'error') {
|