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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c36f2a8b4d7d9445dff7ceeade7c98961444b924b114ea349390fc1dd89e6ed7
4
- data.tar.gz: 8e8022b3e594234cb560d0065463cc3b74c2cf2a97b39271e0c0949ac8d5ff3b
3
+ metadata.gz: 1cfd07c4a4982f58446af9f2deb5230a4225e3c733165b37038ba08fbb8bb29a
4
+ data.tar.gz: 6dcc33af22e42b4a6cd260185f9bae495657ed19307a8f57c3a141d58c411376
5
5
  SHA512:
6
- metadata.gz: df41b2fb7d57d8922330e501a21b4b4418340c204537d3b74af94ebe6ea4b9b07ebfcd239e8bd51c17d8aef5100ad396a4252cde1804297165c029081ec2fc62
7
- data.tar.gz: 6b875cc9aa5b5c8d8c1ab1a2e13c5a5e2348e00b8585a13837dd454b3e78a1230ba25297371936f45757dcd1ce2ec451f24652a4582e9efa3edaa13100132f51
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.** Fast, content-based file hashing.
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 fingerprinting and minification
179
+ # Build with minification
180
180
  bun_bun_bundle build --prod
181
181
 
182
182
  # Development with verbose WebSocket logging
@@ -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 message = JSON.stringify({type})
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
 
@@ -44,10 +44,6 @@ module BunBunBundle
44
44
  entries.key?(key)
45
45
  end
46
46
 
47
- def css_entry_points
48
- entries.keys.select { |k| k.end_with?('.css') }
49
- end
50
-
51
47
  private
52
48
 
53
49
  def find_similar(key, tolerance: 4)
@@ -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[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('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') {
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BunBunBundle
4
- VERSION = '0.6.1'
4
+ VERSION = '0.7.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bun_bun_bundle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wout Fierens