bun_bun_bundle 0.1.1 → 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 +4 -4
- data/README.md +45 -30
- data/lib/bun_bun_bundle/hanami.rb +4 -20
- data/lib/bun_bun_bundle/railtie.rb +1 -7
- data/lib/bun_bun_bundle/version.rb +1 -1
- data/lib/bun_bun_bundle.rb +23 -0
- 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: 74f92b0b7b6bf9ae9cba639bcd548cf447e89ac55d14a121b55926677a75658b
|
|
4
|
+
data.tar.gz: d50ffe4d0477df3390702c9ee1c7797a63e4d3ab32cd4e885db340f12516973f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1b34424077d7ffb800d89c0a1790278524a5c1ea2640c38eefd5f9c6a4c2f7c7fa6e42a06ee08a4082889cb9f524b0ae7594e0da5914d9e29d7d19085c79e194
|
|
7
|
+
data.tar.gz: c7d5c0f4b24c2025c12ad3f1c33a7933f8806bc13a3a0f7e1f6d3b2c3b31fd048237ad5dbb1b07b3686f2d1e196808ddbb99fc08ae9e7552f01826bb211c7eaf
|
data/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
#
|
|
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.
|
|
5
|
-
hot-reloading, fingerprinting, live reload, and a flexible plugin system.
|
|
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
|
|
31
|
+
but nothing is holding you back from enabling them in development as well.
|
|
32
32
|
|
|
33
33
|
### Extensible plugin system
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
imports. Plugins are simple, plain JS files, so you can create your
|
|
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
|
|
42
|
-
are
|
|
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,27 +93,31 @@ stale asset caching.
|
|
|
81
93
|
|
|
82
94
|
## Usage with Hanami
|
|
83
95
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
```ruby
|
|
87
|
-
# config/app.rb
|
|
96
|
+
Hanami ships with its own esbuild-based asset pipeline. Since BunBunBundle
|
|
97
|
+
replaces it entirely, you can clean up the default setup:
|
|
88
98
|
|
|
89
|
-
|
|
90
|
-
|
|
99
|
+
- Remove `gem 'hanami-assets'` from your `Gemfile`
|
|
100
|
+
- Delete `config/assets.js`, `package.json`, and `node_modules/`
|
|
91
101
|
|
|
92
|
-
|
|
102
|
+
1. Set up the Hanami integration:
|
|
93
103
|
|
|
94
104
|
```ruby
|
|
95
105
|
# config/app.rb
|
|
96
106
|
|
|
107
|
+
require 'bun_bun_bundle/hanami'
|
|
108
|
+
|
|
97
109
|
module MyApp
|
|
98
110
|
class App < Hanami::App
|
|
99
|
-
|
|
111
|
+
BunBunBundle.setup(root: root, hanami: config)
|
|
100
112
|
end
|
|
101
113
|
end
|
|
102
114
|
```
|
|
103
115
|
|
|
104
|
-
|
|
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
|
+
|
|
120
|
+
2. Include the helpers in your views:
|
|
105
121
|
|
|
106
122
|
```ruby
|
|
107
123
|
# app/views/helpers.rb
|
|
@@ -116,7 +132,7 @@ stale asset caching.
|
|
|
116
132
|
end
|
|
117
133
|
```
|
|
118
134
|
|
|
119
|
-
|
|
135
|
+
3. Use them in your templates:
|
|
120
136
|
|
|
121
137
|
```erb
|
|
122
138
|
<%= bun_css_tag('css/app.css') %>
|
|
@@ -129,9 +145,7 @@ stale asset caching.
|
|
|
129
145
|
```ruby
|
|
130
146
|
require 'bun_bun_bundle'
|
|
131
147
|
|
|
132
|
-
|
|
133
|
-
BunBunBundle.config = BunBunBundle::Config.load(root: __dir__)
|
|
134
|
-
BunBunBundle.manifest = BunBunBundle::Manifest.load(root: __dir__)
|
|
148
|
+
BunBunBundle.setup(root: __dir__)
|
|
135
149
|
|
|
136
150
|
# Optionally set a CDN host
|
|
137
151
|
BunBunBundle.asset_host = 'https://cdn.example.com'
|
|
@@ -139,7 +153,8 @@ BunBunBundle.asset_host = 'https://cdn.example.com'
|
|
|
139
153
|
|
|
140
154
|
## Helpers
|
|
141
155
|
|
|
142
|
-
All helpers are prefixed with `bun_` to avoid conflicts with framework
|
|
156
|
+
All helpers are prefixed with `bun_` to avoid conflicts with existing framework
|
|
157
|
+
helpers:
|
|
143
158
|
|
|
144
159
|
| Helper | Description |
|
|
145
160
|
| -------------------------------- | ------------------------------------------------ |
|
|
@@ -198,7 +213,7 @@ Place a `config/bun.json` in your project root:
|
|
|
198
213
|
}
|
|
199
214
|
```
|
|
200
215
|
|
|
201
|
-
All values shown above are defaults
|
|
216
|
+
All values shown above are defaults. You only need to specify what you want to
|
|
202
217
|
override.
|
|
203
218
|
|
|
204
219
|
## Plugins
|
|
@@ -259,8 +274,8 @@ your-app/
|
|
|
259
274
|
|
|
260
275
|
BunBunBundle was originally built for [Fluck](https://fluck.site), a
|
|
261
276
|
self-hostable website builder using [Lucky
|
|
262
|
-
Framework](https://luckyframework.org/). I wanted to have a fast
|
|
263
|
-
asset bundler that would
|
|
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.
|
|
264
279
|
|
|
265
280
|
Bun was the natural choice because it does almost everything:
|
|
266
281
|
|
|
@@ -272,10 +287,10 @@ Bun was the natural choice because it does almost everything:
|
|
|
272
287
|
- Extendability with simple plugins
|
|
273
288
|
|
|
274
289
|
It's also fast and reliable. We use this setup heavily in two Lucky apps and it
|
|
275
|
-
is rock solid
|
|
290
|
+
is rock solid. It has since been adopted by Lucky as the default builder.
|
|
276
291
|
|
|
277
|
-
I wanted to have the same setup in my Ruby apps as
|
|
278
|
-
|
|
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!
|
|
279
294
|
|
|
280
295
|
## Contributing
|
|
281
296
|
|
|
@@ -1,15 +1,17 @@
|
|
|
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
|
#
|
|
6
8
|
# Add to your Hanami app's config/app.rb:
|
|
7
9
|
#
|
|
8
|
-
# require
|
|
10
|
+
# require 'bun_bun_bundle/hanami'
|
|
9
11
|
#
|
|
10
12
|
# module MyApp
|
|
11
13
|
# class App < Hanami::App
|
|
12
|
-
#
|
|
14
|
+
# BunBunBundle.setup(root: root, hanami: config)
|
|
13
15
|
# end
|
|
14
16
|
# end
|
|
15
17
|
#
|
|
@@ -25,22 +27,4 @@ module BunBunBundle
|
|
|
25
27
|
# end
|
|
26
28
|
# end
|
|
27
29
|
#
|
|
28
|
-
module HanamiIntegration
|
|
29
|
-
def self.setup(root: Dir.pwd)
|
|
30
|
-
BunBunBundle.config = Config.load(root: root)
|
|
31
|
-
|
|
32
|
-
BunBunBundle.manifest = if BunBunBundle.development?
|
|
33
|
-
Manifest.load(root: root)
|
|
34
|
-
else
|
|
35
|
-
Manifest.load(root: root, retries: 1, delay: 0)
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
# Auto-setup when loaded in a Hanami app.
|
|
42
|
-
if defined?(Hanami)
|
|
43
|
-
Hanami::App.after :configure do
|
|
44
|
-
BunBunBundle::HanamiIntegration.setup(root: root.to_s)
|
|
45
|
-
end
|
|
46
30
|
end
|
|
@@ -13,13 +13,7 @@ module BunBunBundle
|
|
|
13
13
|
|
|
14
14
|
initializer 'bun_bun_bundle.manifest' do |app|
|
|
15
15
|
config.after_initialize do
|
|
16
|
-
BunBunBundle.
|
|
17
|
-
|
|
18
|
-
BunBunBundle.manifest = if BunBunBundle.development?
|
|
19
|
-
Manifest.load(root: app.root.to_s)
|
|
20
|
-
else
|
|
21
|
-
Manifest.load(root: app.root.to_s, retries: 1, delay: 0)
|
|
22
|
-
end
|
|
16
|
+
BunBunBundle.setup(root: app.root)
|
|
23
17
|
end
|
|
24
18
|
end
|
|
25
19
|
|
data/lib/bun_bun_bundle.rb
CHANGED
|
@@ -36,6 +36,19 @@ module BunBunBundle
|
|
|
36
36
|
environment == 'production'
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
+
# Loads config and manifest. Call this from Hanami's config/app.rb or
|
|
40
|
+
# any Rack app's startup.
|
|
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)
|
|
45
|
+
self.config = Config.load(root: root.to_s)
|
|
46
|
+
options = development? ? {} : { retries: 1, delay: 0 }
|
|
47
|
+
self.manifest = Manifest.load(root: root.to_s, **options)
|
|
48
|
+
|
|
49
|
+
configure_hanami(hanami) if hanami
|
|
50
|
+
end
|
|
51
|
+
|
|
39
52
|
# Returns the path to the bundled JS files shipped with the gem.
|
|
40
53
|
def bun_path
|
|
41
54
|
File.expand_path('bun', __dir__)
|
|
@@ -48,6 +61,16 @@ module BunBunBundle
|
|
|
48
61
|
@asset_host = nil
|
|
49
62
|
@environment = nil
|
|
50
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
|
|
51
74
|
end
|
|
52
75
|
end
|
|
53
76
|
|