bun_bun_bundle 0.3.7 → 0.5.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 +22 -5
- data/exe/bun_bun_bundle +7 -7
- data/lib/bun/bake.js +1 -0
- data/lib/bun/bun_bundle.js +8 -4
- data/lib/bun/plugins/index.js +2 -1
- data/lib/bun_bun_bundle/config.rb +2 -2
- data/lib/bun_bun_bundle/helpers.rb +19 -7
- data/lib/bun_bun_bundle/reload_tag.rb +1 -1
- data/lib/bun_bun_bundle/safe_html.rb +2 -2
- 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: 4337760da846f05fed302c7aa1da9767ed8f26d0ae1eaabf3f550d79670a0542
|
|
4
|
+
data.tar.gz: f057d109b5f3b89a72b63b4ae0c1022fb9cc71cc4d0aa2a4ba53c03aec9366bf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 98d7a220fd690cb23664ff8589c0915bfa31d476e6d864127f4f7ae6a8d9ea9277fdb25b25b8d3c158218125f2c68ac5a10cd9db3e8723b4e92f2c23fa4ad264
|
|
7
|
+
data.tar.gz: a7b2ea22fbe70b7077de804b4bdd597bdabaf53bc730b251d825e0e94d8d67e43799f66ba4e840191532e0a68f4ea64633cee6eec2be8bba86f613d3629664cf
|
data/README.md
CHANGED
|
@@ -14,6 +14,9 @@ Works with Rails, Hanami, or any Rack app.
|
|
|
14
14
|
- **Extensible.** Plugins are simple, tiny JavaScript files.
|
|
15
15
|
- **One dependency: Bun.** Everything is included, no other dev dependencies.
|
|
16
16
|
|
|
17
|
+
[](https://codeberg.org/w0u7/bun_bun_bundle/actions?workflow=test.yml)
|
|
18
|
+
[](https://rubygems.org/gems/bun_bun_bundle)
|
|
19
|
+
|
|
17
20
|
> [!Note]
|
|
18
21
|
> The original repository is hosted at
|
|
19
22
|
> [Codeberg](https://codeberg.org/w0u7/bun_bun_bundle). The [GitHub
|
|
@@ -152,6 +155,15 @@ All tag helpers accept additional HTML attributes:
|
|
|
152
155
|
<%= bun_img_tag('images/logo.png', alt: 'My App', class: 'logo') %>
|
|
153
156
|
```
|
|
154
157
|
|
|
158
|
+
Data and aria attributes can be passed as nested hashes (Rails-style) or with
|
|
159
|
+
underscores (Lucky-style). Underscores are converted to hyphens automatically:
|
|
160
|
+
|
|
161
|
+
```erb
|
|
162
|
+
<%= bun_js_tag('js/app.js', data: { turbo_track: "reload" }) %>
|
|
163
|
+
<%= bun_js_tag('js/app.js', data_turbo_track: "reload") %>
|
|
164
|
+
<%# Both render: data-turbo-track="reload" %>
|
|
165
|
+
```
|
|
166
|
+
|
|
155
167
|
## CLI
|
|
156
168
|
|
|
157
169
|
Build your assets using the bundled CLI (`bbb` is available as a shorter
|
|
@@ -161,11 +173,14 @@ alias):
|
|
|
161
173
|
# Development: builds, watches, and starts the live reload server
|
|
162
174
|
bun_bun_bundle dev
|
|
163
175
|
|
|
164
|
-
#
|
|
176
|
+
# Build assets
|
|
165
177
|
bun_bun_bundle build
|
|
166
178
|
|
|
167
|
-
#
|
|
168
|
-
bun_bun_bundle
|
|
179
|
+
# Build with fingerprinting and minification
|
|
180
|
+
bun_bun_bundle build --prod
|
|
181
|
+
|
|
182
|
+
# Development with verbose WebSocket logging
|
|
183
|
+
bun_bun_bundle dev --debug
|
|
169
184
|
```
|
|
170
185
|
|
|
171
186
|
> [!NOTE]
|
|
@@ -384,7 +399,7 @@ COPY package.json bun.lock ./
|
|
|
384
399
|
RUN bun install --frozen-lockfile
|
|
385
400
|
|
|
386
401
|
COPY . .
|
|
387
|
-
RUN bundle exec bun_bun_bundle build
|
|
402
|
+
RUN bundle exec bun_bun_bundle build --prod
|
|
388
403
|
```
|
|
389
404
|
|
|
390
405
|
> [!NOTE]
|
|
@@ -411,7 +426,9 @@ It's also fast and reliable. We use this setup heavily in two Lucky apps and it
|
|
|
411
426
|
is rock solid. It has since been adopted by Lucky as the default builder.
|
|
412
427
|
|
|
413
428
|
This Gem was born because I wanted to have the same setup in my Ruby apps as
|
|
414
|
-
well.
|
|
429
|
+
well. We now use it for an important Rails app in production.
|
|
430
|
+
|
|
431
|
+
I hope you enjoy it too!
|
|
415
432
|
|
|
416
433
|
## Contributing
|
|
417
434
|
|
data/exe/bun_bun_bundle
CHANGED
|
@@ -12,23 +12,23 @@ case command
|
|
|
12
12
|
when 'dev', 'watch'
|
|
13
13
|
exec('bun', 'run', bake, '--dev', *flags)
|
|
14
14
|
when 'build'
|
|
15
|
-
exec('bun', 'run', bake,
|
|
15
|
+
exec('bun', 'run', bake, *flags)
|
|
16
16
|
else
|
|
17
17
|
puts <<~USAGE
|
|
18
18
|
Usage: bun_bun_bundle <command> [flags]
|
|
19
19
|
|
|
20
20
|
Commands:
|
|
21
21
|
dev Start development server with live reload and CSS hot-reloading
|
|
22
|
-
build Build assets
|
|
22
|
+
build Build assets
|
|
23
23
|
|
|
24
24
|
Flags:
|
|
25
|
-
--prod
|
|
26
|
-
--
|
|
25
|
+
--prod Enable minification and fingerprinting
|
|
26
|
+
--debug Enable verbose WebSocket logging
|
|
27
27
|
|
|
28
28
|
Examples:
|
|
29
|
-
bun_bun_bundle dev
|
|
30
|
-
bun_bun_bundle
|
|
31
|
-
bun_bun_bundle build
|
|
29
|
+
bun_bun_bundle dev # development with live reload
|
|
30
|
+
bun_bun_bundle build # build assets
|
|
31
|
+
bun_bun_bundle build --prod # build with fingerprinting and minification
|
|
32
32
|
|
|
33
33
|
Configuration:
|
|
34
34
|
Place a config/bun.json in your project root to customize settings.
|
data/lib/bun/bake.js
CHANGED
data/lib/bun/bun_bundle.js
CHANGED
|
@@ -18,13 +18,15 @@ export default {
|
|
|
18
18
|
root: process.cwd(),
|
|
19
19
|
config: null,
|
|
20
20
|
manifest: {},
|
|
21
|
+
debug: false,
|
|
21
22
|
dev: false,
|
|
22
23
|
prod: false,
|
|
23
24
|
wsClients: new Set(),
|
|
24
25
|
watchTimers: new Map(),
|
|
25
26
|
plugins: [],
|
|
26
27
|
|
|
27
|
-
flags({dev, prod}) {
|
|
28
|
+
flags({debug, dev, prod}) {
|
|
29
|
+
if (debug != null) this.debug = debug
|
|
28
30
|
if (dev != null) this.dev = dev
|
|
29
31
|
if (prod != null) this.prod = prod
|
|
30
32
|
},
|
|
@@ -87,7 +89,8 @@ export default {
|
|
|
87
89
|
const outDir = join(this.outDir, type)
|
|
88
90
|
mkdirSync(outDir, {recursive: true})
|
|
89
91
|
|
|
90
|
-
const
|
|
92
|
+
const raw = this.config.entryPoints[type]
|
|
93
|
+
const entries = Array.isArray(raw) ? raw : [raw]
|
|
91
94
|
const ext = `.${type}`
|
|
92
95
|
|
|
93
96
|
for (const entry of entries) {
|
|
@@ -266,6 +269,7 @@ export default {
|
|
|
266
269
|
await this.watch()
|
|
267
270
|
|
|
268
271
|
const {host, port, secure} = this.config.devServer
|
|
272
|
+
const debug = this.debug
|
|
269
273
|
const wsClients = this.wsClients
|
|
270
274
|
|
|
271
275
|
Bun.serve({
|
|
@@ -278,11 +282,11 @@ export default {
|
|
|
278
282
|
websocket: {
|
|
279
283
|
open(ws) {
|
|
280
284
|
wsClients.add(ws)
|
|
281
|
-
console.log(` ▸ Client connected (${wsClients.size})\n\n`)
|
|
285
|
+
if (debug) console.log(` ▸ Client connected (${wsClients.size})\n\n`)
|
|
282
286
|
},
|
|
283
287
|
close(ws) {
|
|
284
288
|
wsClients.delete(ws)
|
|
285
|
-
console.log(` ▸ Client disconnected (${wsClients.size})\n\n`)
|
|
289
|
+
if (debug) console.log(` ▸ Client disconnected (${wsClients.size})\n\n`)
|
|
286
290
|
},
|
|
287
291
|
message() {}
|
|
288
292
|
}
|
data/lib/bun/plugins/index.js
CHANGED
|
@@ -20,7 +20,8 @@ function transformPipeline(type, transforms) {
|
|
|
20
20
|
let content = await Bun.file(args.path).text()
|
|
21
21
|
for (const transform of transforms)
|
|
22
22
|
content = await transform(content, args)
|
|
23
|
-
|
|
23
|
+
const ext = args.path.split('.').pop()
|
|
24
|
+
return {contents: content, loader: ext}
|
|
24
25
|
})
|
|
25
26
|
}
|
|
26
27
|
}
|
|
@@ -28,8 +28,8 @@ module BunBunBundle
|
|
|
28
28
|
attr_reader :js, :css
|
|
29
29
|
|
|
30
30
|
def initialize(data = {})
|
|
31
|
-
@js = data.fetch('js', %w[app/assets/js/app.js])
|
|
32
|
-
@css = data.fetch('css', %w[app/assets/css/app.css])
|
|
31
|
+
@js = Array(data.fetch('js', %w[app/assets/js/app.js]))
|
|
32
|
+
@css = Array(data.fetch('css', %w[app/assets/css/app.css]))
|
|
33
33
|
end
|
|
34
34
|
end
|
|
35
35
|
|
|
@@ -35,7 +35,7 @@ module BunBunBundle
|
|
|
35
35
|
def bun_js_tag(source, **options)
|
|
36
36
|
src = bun_asset(source)
|
|
37
37
|
attrs = { type: 'text/javascript' }.merge(options).merge(src: src)
|
|
38
|
-
|
|
38
|
+
bun_safe(%(<script #{bun_html_attrs(attrs)}></script>))
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
# Generates a <link> tag for a CSS entry point.
|
|
@@ -46,7 +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
|
-
|
|
49
|
+
bun_safe(%(<link #{bun_html_attrs(attrs)}>))
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
# Generates an <img> tag for an image asset.
|
|
@@ -58,18 +58,30 @@ module BunBunBundle
|
|
|
58
58
|
src = bun_asset(source)
|
|
59
59
|
alt = options.delete(:alt) || File.basename(source, '.*').tr('-_', ' ').capitalize
|
|
60
60
|
attrs = { alt: alt }.merge(options).merge(src: src)
|
|
61
|
-
|
|
61
|
+
bun_safe(%(<img #{bun_html_attrs(attrs)}>))
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
private
|
|
65
65
|
|
|
66
|
-
def
|
|
67
|
-
hash.compact.map do |k, v|
|
|
68
|
-
|
|
66
|
+
def bun_html_attrs(hash)
|
|
67
|
+
bun_flatten_attrs(hash).compact.map do |k, v|
|
|
68
|
+
k = k.to_s.tr('_', '-')
|
|
69
|
+
v == true ? k : %(#{k}="#{bun_escape_attr(v)}")
|
|
69
70
|
end.join(' ')
|
|
70
71
|
end
|
|
71
72
|
|
|
72
|
-
def
|
|
73
|
+
def bun_flatten_attrs(hash, prefix: nil)
|
|
74
|
+
hash.each_with_object({}) do |(k, v), flat|
|
|
75
|
+
key = prefix ? :"#{prefix}_#{k}" : k
|
|
76
|
+
if v.is_a?(Hash)
|
|
77
|
+
flat.merge!(bun_flatten_attrs(v, prefix: key))
|
|
78
|
+
else
|
|
79
|
+
flat[key] = v
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def bun_escape_attr(value)
|
|
73
85
|
value.to_s.gsub('&', '&').gsub('"', '"').gsub('<', '<').gsub('>', '>')
|
|
74
86
|
end
|
|
75
87
|
end
|