bun_bun_bundle 0.7.0 → 0.8.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 +3 -9
- data/lib/bun_bun_bundle/helpers.rb +10 -3
- data/lib/bun_bun_bundle/manifest.rb +4 -0
- data/lib/bun_bun_bundle/reload_tag.rb +11 -4
- 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: 17cca9ef2aafb44594e5ea2e2abfcd6dfa4a35b3af61f636a0a90ee57383d21a
|
|
4
|
+
data.tar.gz: '08ef01b7f75cb09e069e62cd40c477f58ea5c78da6e16761066e70a4970f8f7f'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d515a1e655140edc0cfe616ff3aafaada50844eea8941700d406f9a5f560406a0da79302653ee665e0a92051175b364e845fdabfec105ceba13cbf03b30f3029
|
|
7
|
+
data.tar.gz: cb9386659db82669c47ec2a82982137d3d5e0b44a95b5c13aee0afcdee7b2a889def2b1dc63f1918fa665b9dac83e9cafd912c2d7d23b37c7748c9b02e0938f4
|
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.** Fast, content-based file hashing.
|
|
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 |
|
|
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 minification
|
|
179
|
+
# Build with fingerprinting and 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,6 +80,8 @@ export default {
|
|
|
80
80
|
},
|
|
81
81
|
|
|
82
82
|
fingerprint(name, ext, content) {
|
|
83
|
+
if (!this.prod) return `${name}${ext}`
|
|
84
|
+
|
|
83
85
|
const hash = Bun.hash(content).toString(16).slice(0, 8)
|
|
84
86
|
return `${name}-${hash}${ext}`
|
|
85
87
|
},
|
|
@@ -209,15 +211,7 @@ export default {
|
|
|
209
211
|
|
|
210
212
|
reload(type = 'full') {
|
|
211
213
|
setTimeout(() => {
|
|
212
|
-
const
|
|
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)
|
|
214
|
+
const message = JSON.stringify({type})
|
|
221
215
|
for (const client of this.wsClients) {
|
|
222
216
|
try {
|
|
223
217
|
client.send(message)
|
|
@@ -44,9 +44,9 @@ module BunBunBundle
|
|
|
44
44
|
# # => '<link href="/assets/css/app.css" type="text/css" rel="stylesheet">'
|
|
45
45
|
#
|
|
46
46
|
def bun_css_tag(source, **options)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
attrs = { type: 'text/css', rel: 'stylesheet' }
|
|
48
|
+
.merge(options)
|
|
49
|
+
.merge(href: bun_href_with_timestamp(bun_asset(source)))
|
|
50
50
|
bun_safe(%(<link #{bun_html_attrs(attrs)}>))
|
|
51
51
|
end
|
|
52
52
|
|
|
@@ -85,5 +85,12 @@ module BunBunBundle
|
|
|
85
85
|
def bun_escape_attr(value)
|
|
86
86
|
value.to_s.gsub('&', '&').gsub('"', '"').gsub('<', '<').gsub('>', '>')
|
|
87
87
|
end
|
|
88
|
+
|
|
89
|
+
def bun_href_with_timestamp(href)
|
|
90
|
+
return href unless href.start_with?(BunBunBundle.config.public_path)
|
|
91
|
+
return href if href.match?(/-[0-9a-f]{8}\.css$/)
|
|
92
|
+
|
|
93
|
+
"#{href}#{href.include?('?') ? '&' : '?'}bust=#{(Time.now.to_f * 1000).to_i}"
|
|
94
|
+
end
|
|
88
95
|
end
|
|
89
96
|
end
|
|
@@ -22,10 +22,14 @@ 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
|
|
25
28
|
|
|
26
29
|
html = <<~HTML
|
|
27
30
|
<script>
|
|
28
31
|
(() => {
|
|
32
|
+
const cssPaths = #{css_paths.to_json};
|
|
29
33
|
const ws = new WebSocket('#{config.dev_server.ws_url}')
|
|
30
34
|
let connected = false
|
|
31
35
|
|
|
@@ -33,10 +37,13 @@ module BunBunBundle
|
|
|
33
37
|
const data = JSON.parse(event.data)
|
|
34
38
|
|
|
35
39
|
if (data.type === 'css') {
|
|
36
|
-
document.querySelectorAll('link[
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
document.querySelectorAll('link[rel="stylesheet"]').forEach(link => {
|
|
41
|
+
const linkPath = new URL(link.href).pathname.split('?')[0]
|
|
42
|
+
if (cssPaths.some(p => linkPath.startsWith(p))) {
|
|
43
|
+
const url = new URL(link.href)
|
|
44
|
+
url.searchParams.set('bust', Date.now())
|
|
45
|
+
link.href = url.toString()
|
|
46
|
+
}
|
|
40
47
|
})
|
|
41
48
|
console.log('\\u25b8 CSS reloaded')
|
|
42
49
|
} else if (data.type === 'error') {
|