bun_bun_bundle 0.1.2 → 0.2.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: c51a065b214293e85467dfdd10f2c84bf763f65fe27d0b549b175ea7448563bf
4
- data.tar.gz: f2d86b5d3650797b617fa3ecee6d3dac119d97850749bc830172bfa12cb83dfe
3
+ metadata.gz: 74f92b0b7b6bf9ae9cba639bcd548cf447e89ac55d14a121b55926677a75658b
4
+ data.tar.gz: d50ffe4d0477df3390702c9ee1c7797a63e4d3ab32cd4e885db340f12516973f
5
5
  SHA512:
6
- metadata.gz: c87530160b4f6829e32f7fc82c4f0d9180aa13b03089011fdb237d8daa4973453bd9cd074bd0402736f7fcab49e7d40c98f9b7fbb1a094aa07f718cd94ca9ac4
7
- data.tar.gz: 0cbad61b7eff7af29f38cab146f09941a8f3dbd9354a1c470d36a35f94bbb36484543f7a06ef27e4810f2a1f51becb00026c7206de30e6b0049334cd224127fd
6
+ metadata.gz: 1b34424077d7ffb800d89c0a1790278524a5c1ea2640c38eefd5f9c6a4c2f7c7fa6e42a06ee08a4082889cb9f524b0ae7594e0da5914d9e29d7d19085c79e194
7
+ data.tar.gz: c7d5c0f4b24c2025c12ad3f1c33a7933f8806bc13a3a0f7e1f6d3b2c3b31fd048237ad5dbb1b07b3686f2d1e196808ddbb99fc08ae9e7552f01826bb211c7eaf
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
- # BunBunBundle
1
+ # Bun, Bun, Bundle
2
2
 
3
3
  A self-contained asset bundler for Ruby powered by [Bun](https://bun.sh). No
4
- development dependencies, no complex configuration. Fast builds with CSS
5
- hot-reloading, fingerprinting, live reload, and a flexible plugin system. Works
6
- with Rails, Hanami, or any Rack app.
4
+ development dependencies, no complex configuration. Lightning fast builds with
5
+ CSS hot-reloading, fingerprinting, live reload, and a flexible plugin system.
6
+ Works with Rails, Hanami, or any Rack app.
7
7
 
8
8
  ## Why use BunBunBundle?
9
9
 
@@ -28,18 +28,18 @@ browsers always fetch the right version.
28
28
 
29
29
  Development and production builds go through the exact same pipeline. The only
30
30
  differences are fingerprinting and minification being enabled in production,
31
- but nothing is holding you back form them in development as well.
31
+ but nothing is holding you back from enabling them in development as well.
32
32
 
33
33
  ### Extensible plugin system
34
34
 
35
- Comes with built-in plugins for CSS glob imports, root aliases, and JS glob
36
- imports. Plugins are simple, plain JS files, so you can create your own JS/CSS
37
- transformers, and raw Bun plugins are supported as well.
35
+ BunBunBundle comes with built-in plugins for CSS glob imports, root aliases,
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
38
 
39
39
  ### Just one dependency: Bun
40
40
 
41
- The bundler ships with the gem. Bun is the only external requirement, so there
42
- are zero dev dependencies.
41
+ The bundler ships with the gem. Bun is the only external requirement, so other
42
+ than that, there are no dev dependencies.
43
43
 
44
44
  ## Installation
45
45
 
@@ -59,6 +59,18 @@ are zero dev dependencies.
59
59
 
60
60
  ## Usage with Rails
61
61
 
62
+ BunBunBundle completely bypasses the Rails asset pipeline. If you're adding it
63
+ to an existing app, you can remove Sprockets/Propshaft:
64
+
65
+ - Remove `gem 'sprockets-rails'` or `gem 'propshaft'` from your `Gemfile`
66
+ - Delete `config/initializers/assets.rb` if present
67
+
68
+ For new apps, generate them without the asset pipeline:
69
+
70
+ ```sh
71
+ rails new myapp --minimal --skip-asset-pipeline --skip-javascript
72
+ ```
73
+
62
74
  The gem auto-configures itself through a Railtie. All helpers are available in
63
75
  your views immediately:
64
76
 
@@ -81,7 +93,13 @@ stale asset caching.
81
93
 
82
94
  ## Usage with Hanami
83
95
 
84
- 1. Require the Hanami integration:
96
+ Hanami ships with its own esbuild-based asset pipeline. Since BunBunBundle
97
+ replaces it entirely, you can clean up the default setup:
98
+
99
+ - Remove `gem 'hanami-assets'` from your `Gemfile`
100
+ - Delete `config/assets.js`, `package.json`, and `node_modules/`
101
+
102
+ 1. Set up the Hanami integration:
85
103
 
86
104
  ```ruby
87
105
  # config/app.rb
@@ -90,12 +108,15 @@ stale asset caching.
90
108
 
91
109
  module MyApp
92
110
  class App < Hanami::App
93
- BunBunBundle.setup(root: root)
94
- config.middleware.use BunBunBundle::DevCacheMiddleware if Hanami.env?(:development)
111
+ BunBunBundle.setup(root: root, hanami: config)
95
112
  end
96
113
  end
97
114
  ```
98
115
 
116
+ This loads the manifest, and in development automatically registers the
117
+ cache-busting middleware and configures the CSP to allow the live reload
118
+ script and WebSocket connection.
119
+
99
120
  2. Include the helpers in your views:
100
121
 
101
122
  ```ruby
@@ -111,7 +132,7 @@ stale asset caching.
111
132
  end
112
133
  ```
113
134
 
114
- 4. Use them in your templates:
135
+ 3. Use them in your templates:
115
136
 
116
137
  ```erb
117
138
  <%= bun_css_tag('css/app.css') %>
@@ -132,7 +153,8 @@ BunBunBundle.asset_host = 'https://cdn.example.com'
132
153
 
133
154
  ## Helpers
134
155
 
135
- All helpers are prefixed with `bun_` to avoid conflicts with framework helpers:
156
+ All helpers are prefixed with `bun_` to avoid conflicts with existing framework
157
+ helpers:
136
158
 
137
159
  | Helper | Description |
138
160
  | -------------------------------- | ------------------------------------------------ |
@@ -191,7 +213,7 @@ Place a `config/bun.json` in your project root:
191
213
  }
192
214
  ```
193
215
 
194
- All values shown above are defaults, you only need to specify what you want to
216
+ All values shown above are defaults. You only need to specify what you want to
195
217
  override.
196
218
 
197
219
  ## Plugins
@@ -252,8 +274,8 @@ your-app/
252
274
 
253
275
  BunBunBundle was originally built for [Fluck](https://fluck.site), a
254
276
  self-hostable website builder using [Lucky
255
- Framework](https://luckyframework.org/). I wanted to have a fast, comprehensive
256
- asset bundler that would not require too much maintenance in the long term.
277
+ Framework](https://luckyframework.org/). I wanted to have a fast and modern
278
+ asset bundler that would require minimal maintenance in the long term.
257
279
 
258
280
  Bun was the natural choice because it does almost everything:
259
281
 
@@ -265,10 +287,10 @@ Bun was the natural choice because it does almost everything:
265
287
  - Extendability with simple plugins
266
288
 
267
289
  It's also fast and reliable. We use this setup heavily in two Lucky apps and it
268
- is rock solid, and it has since been adopted by Lucky as the default builder.
290
+ is rock solid. It has since been adopted by Lucky as the default builder.
269
291
 
270
- I wanted to have the same setup in my Ruby apps as well, that's when this Gem
271
- was born. I hope you enjoy it too!
292
+ This Gem was born because I wanted to have the same setup in my Ruby apps as
293
+ well. I hope you enjoy it too!
272
294
 
273
295
  ## Contributing
274
296
 
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'bun_bun_bundle'
4
+
3
5
  module BunBunBundle
4
6
  # Hanami integration for BunBunBundle.
5
7
  #
@@ -9,8 +11,7 @@ module BunBunBundle
9
11
  #
10
12
  # module MyApp
11
13
  # class App < Hanami::App
12
- # BunBunBundle.setup(root: root)
13
- # config.middleware.use BunBunBundle::DevCacheMiddleware if Hanami.env?(:development)
14
+ # BunBunBundle.setup(root: root, hanami: config)
14
15
  # end
15
16
  # end
16
17
  #
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BunBunBundle
4
- VERSION = '0.1.2'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -38,10 +38,15 @@ module BunBunBundle
38
38
 
39
39
  # Loads config and manifest. Call this from Hanami's config/app.rb or
40
40
  # any Rack app's startup.
41
- def setup(root: Dir.pwd)
41
+ #
42
+ # Pass `hanami: config` from within a Hanami::App class body to
43
+ # automatically register middleware and configure CSP for development.
44
+ def setup(root: Dir.pwd, hanami: nil)
42
45
  self.config = Config.load(root: root.to_s)
43
46
  options = development? ? {} : { retries: 1, delay: 0 }
44
47
  self.manifest = Manifest.load(root: root.to_s, **options)
48
+
49
+ configure_hanami(hanami) if hanami
45
50
  end
46
51
 
47
52
  # Returns the path to the bundled JS files shipped with the gem.
@@ -56,6 +61,16 @@ module BunBunBundle
56
61
  @asset_host = nil
57
62
  @environment = nil
58
63
  end
64
+
65
+ private
66
+
67
+ def configure_hanami(hanami_config)
68
+ return unless development?
69
+
70
+ hanami_config.middleware.use DevCacheMiddleware
71
+ hanami_config.actions.content_security_policy[:script_src] += " 'unsafe-inline'"
72
+ hanami_config.actions.content_security_policy[:connect_src] += " #{config.dev_server.ws_url}"
73
+ end
59
74
  end
60
75
  end
61
76
 
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.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wout Fierens