bun_bun_bundle 0.2.0 → 0.3.1
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 +115 -17
- data/lib/bun/bun_bundle.js +1 -1
- data/lib/bun/plugins/aliases.js +9 -0
- data/lib/bun/plugins/index.js +2 -2
- data/lib/bun_bun_bundle/version.rb +1 -1
- metadata +2 -2
- data/lib/bun/plugins/cssAliases.js +0 -10
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: af9d8cfb9a1c9760525e72775ee8ad25d2a281b5b35574a16e42518bc91117dd
|
|
4
|
+
data.tar.gz: de954cd7b5d7d263e78c59165aac8e825ac6fef69eee807dad59c6379957b94e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 33f20c3b906cb29b8a663b396cb1794e08f3775364f4d54573bdd75f1d5acde298df054c1a2d894008657018dff00b521c7b12c37e532737be038d77e768da55
|
|
7
|
+
data.tar.gz: ad0264ca27cc57d871d7b38a6bdab12a96ab72674b543503b24fdafe4cc949b26e490e6608e6aebb4313c45363aea082b34f9ffc4d44d6e7785787822f25ac6d
|
data/README.md
CHANGED
|
@@ -32,7 +32,7 @@ but nothing is holding you back from enabling them in development as well.
|
|
|
32
32
|
|
|
33
33
|
### Extensible plugin system
|
|
34
34
|
|
|
35
|
-
BunBunBundle comes with built-in plugins for CSS glob imports,
|
|
35
|
+
BunBunBundle comes with built-in plugins for root aliases, CSS glob imports,
|
|
36
36
|
and JS glob imports. Plugins are simple, plain JS files, so you can create your
|
|
37
37
|
own JS/CSS transformers, and raw Bun plugins are supported as well.
|
|
38
38
|
|
|
@@ -207,8 +207,8 @@ Place a `config/bun.json` in your project root:
|
|
|
207
207
|
"secure": false
|
|
208
208
|
},
|
|
209
209
|
"plugins": {
|
|
210
|
-
"css": ["
|
|
211
|
-
"js": ["jsGlobs"]
|
|
210
|
+
"css": ["aliases", "cssGlobs"],
|
|
211
|
+
"js": ["aliases", "jsGlobs"]
|
|
212
212
|
}
|
|
213
213
|
}
|
|
214
214
|
```
|
|
@@ -218,35 +218,133 @@ override.
|
|
|
218
218
|
|
|
219
219
|
## Plugins
|
|
220
220
|
|
|
221
|
-
Three plugins are included out of the box
|
|
221
|
+
Three plugins are included out of the box.
|
|
222
222
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
223
|
+
### `aliases`
|
|
224
|
+
|
|
225
|
+
Resolves `$/` root aliases to absolute paths in both CSS and JS files. This
|
|
226
|
+
lets you reference assets and modules from the project root without worrying
|
|
227
|
+
about relative paths.
|
|
228
|
+
|
|
229
|
+
In CSS:
|
|
230
|
+
|
|
231
|
+
```css
|
|
232
|
+
@import '$/app/assets/css/reset.css';
|
|
233
|
+
|
|
234
|
+
.logo {
|
|
235
|
+
background: url('$/app/assets/images/logo.png');
|
|
236
|
+
}
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
In JS:
|
|
240
|
+
|
|
241
|
+
```javascript
|
|
242
|
+
import utils from '$/lib/utils.js'
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
All `$/` references are resolved to your project root.
|
|
246
|
+
|
|
247
|
+
### `cssGlobs`
|
|
248
|
+
|
|
249
|
+
Expands glob patterns in CSS `@import` statements. Instead of manually listing
|
|
250
|
+
every file, you can import an entire directory at once:
|
|
251
|
+
|
|
252
|
+
```css
|
|
253
|
+
@import './components/**/*.css';
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
This will be expanded into individual `@import` lines for each matching file,
|
|
257
|
+
sorted alphabetically.
|
|
258
|
+
|
|
259
|
+
> [!NOTE]
|
|
260
|
+
> A warning is logged if the pattern matches no files.
|
|
261
|
+
|
|
262
|
+
### `jsGlobs`
|
|
263
|
+
|
|
264
|
+
Compiles glob imports into an object that maps file paths to their default
|
|
265
|
+
exports. Use the special `glob:` prefix in an import statement:
|
|
266
|
+
|
|
267
|
+
```javascript
|
|
268
|
+
import components from 'glob:./components/**/*.js'
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
This will generate individual imports and builds an object mapping. For
|
|
272
|
+
example:
|
|
273
|
+
|
|
274
|
+
```javascript
|
|
275
|
+
import _glob_components_theme from './components/theme.js'
|
|
276
|
+
import _glob_components_shared_tooltip from './components/shared/tooltip.js'
|
|
277
|
+
const components = {
|
|
278
|
+
'components/theme': _glob_components_theme,
|
|
279
|
+
'components/shared/tooltip': _glob_components_shared_tooltip
|
|
280
|
+
}
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
> [!NOTE]
|
|
284
|
+
> If no files match the pattern, an empty object is assigned.
|
|
228
285
|
|
|
229
286
|
### Custom plugins
|
|
230
287
|
|
|
231
|
-
|
|
288
|
+
Custom plugins are JS files referenced by their path in the config. Each file
|
|
289
|
+
must export a factory function that receives a context object with `root`
|
|
290
|
+
(project root path) and `prod` (boolean indicating production mode). What the
|
|
291
|
+
factory returns determines the plugin type.
|
|
292
|
+
|
|
293
|
+
#### Simple transform plugins
|
|
294
|
+
|
|
295
|
+
A simple transform plugin returns a function that receives the file content as
|
|
296
|
+
a string and an `args` object with the file's `path`. It should return the
|
|
297
|
+
transformed content. The transform can be synchronous or asynchronous.
|
|
298
|
+
|
|
299
|
+
Transforms are chained in the order they appear in the config, so each
|
|
300
|
+
transform receives the output of the previous one.
|
|
232
301
|
|
|
233
302
|
```javascript
|
|
234
303
|
// config/bun/banner.js
|
|
235
304
|
|
|
236
|
-
export default function banner({
|
|
237
|
-
return
|
|
238
|
-
const stamp = prod ?
|
|
239
|
-
return `/* My App${stamp} */\n${content}
|
|
240
|
-
}
|
|
305
|
+
export default function banner({prod}) {
|
|
306
|
+
return content => {
|
|
307
|
+
const stamp = prod ? '' : ` (dev build ${new Date().toISOString()})`
|
|
308
|
+
return `/* My App${stamp} */\n${content}`
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
#### Raw Bun plugins
|
|
314
|
+
|
|
315
|
+
If the factory returns an object with a `setup` method instead of a function,
|
|
316
|
+
it is treated as a raw
|
|
317
|
+
[Bun plugin](https://bun.sh/docs/bundler/plugins). This gives you full access
|
|
318
|
+
to Bun's plugin API, including `onLoad`, `onResolve`, and custom loaders.
|
|
319
|
+
|
|
320
|
+
```javascript
|
|
321
|
+
// config/bun/svg.js
|
|
322
|
+
|
|
323
|
+
export default function svg() {
|
|
324
|
+
return {
|
|
325
|
+
name: 'svg-loader',
|
|
326
|
+
setup(build) {
|
|
327
|
+
build.onLoad({filter: /\.svg$/}, async args => {
|
|
328
|
+
const text = await Bun.file(args.path).text()
|
|
329
|
+
return {
|
|
330
|
+
contents: `export default ${JSON.stringify(text)}`,
|
|
331
|
+
loader: 'js'
|
|
332
|
+
}
|
|
333
|
+
})
|
|
334
|
+
}
|
|
335
|
+
}
|
|
241
336
|
}
|
|
242
337
|
```
|
|
243
338
|
|
|
244
|
-
|
|
339
|
+
#### Registering custom plugins
|
|
340
|
+
|
|
341
|
+
Reference custom plugins by their file path in your config:
|
|
245
342
|
|
|
246
343
|
```json
|
|
247
344
|
{
|
|
248
345
|
"plugins": {
|
|
249
|
-
"css": ["
|
|
346
|
+
"css": ["aliases", "cssGlobs", "config/bun/banner.js"],
|
|
347
|
+
"js": ["aliases", "jsGlobs", "config/bun/svg.js"]
|
|
250
348
|
}
|
|
251
349
|
}
|
|
252
350
|
```
|
data/lib/bun/bun_bundle.js
CHANGED
|
@@ -42,7 +42,7 @@ export default {
|
|
|
42
42
|
loadConfig() {
|
|
43
43
|
const defaults = {
|
|
44
44
|
entryPoints: {js: ['app/assets/js/app.js'], css: ['app/assets/css/app.css']},
|
|
45
|
-
plugins: {css: ['
|
|
45
|
+
plugins: {css: ['aliases', 'cssGlobs'], js: ['aliases', 'jsGlobs']},
|
|
46
46
|
staticDirs: ['app/assets/images', 'app/assets/fonts'],
|
|
47
47
|
outDir: 'public/assets',
|
|
48
48
|
publicPath: '/assets',
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const REGEX = /(url\(\s*['"]?|(?<!\w)['"])\$\//g
|
|
2
|
+
|
|
3
|
+
// Resolves `$/` root aliases in CSS url() references and JS/CSS imports.
|
|
4
|
+
// e.g. url('$/app/assets/images/foo.png') → url('/absolute/root/app/assets/images/foo.png')
|
|
5
|
+
// import x from '$/lib/utils.js' → import x from '/absolute/root/lib/utils.js'
|
|
6
|
+
// @import '$/app/assets/css/reset.css' → @import '/absolute/root/app/assets/css/reset.css'
|
|
7
|
+
export default function aliases({root}) {
|
|
8
|
+
return content => content.replace(REGEX, `$1${root}/`)
|
|
9
|
+
}
|
data/lib/bun/plugins/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {join} from 'path'
|
|
2
|
-
import
|
|
2
|
+
import aliases from './aliases.js'
|
|
3
3
|
import cssGlobs from './cssGlobs.js'
|
|
4
4
|
import jsGlobs from './jsGlobs.js'
|
|
5
5
|
|
|
6
|
-
const builtins = {
|
|
6
|
+
const builtins = {aliases, cssGlobs, jsGlobs}
|
|
7
7
|
const TYPE_REGEXES = {
|
|
8
8
|
css: /\.css$/,
|
|
9
9
|
js: /\.(js|ts|jsx|tsx)$/
|
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.
|
|
4
|
+
version: 0.3.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Wout Fierens
|
|
@@ -36,7 +36,7 @@ files:
|
|
|
36
36
|
- exe/bun_bun_bundle
|
|
37
37
|
- lib/bun/bake.js
|
|
38
38
|
- lib/bun/bun_bundle.js
|
|
39
|
-
- lib/bun/plugins/
|
|
39
|
+
- lib/bun/plugins/aliases.js
|
|
40
40
|
- lib/bun/plugins/cssGlobs.js
|
|
41
41
|
- lib/bun/plugins/index.js
|
|
42
42
|
- lib/bun/plugins/jsGlobs.js
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import {join} from 'path'
|
|
2
|
-
|
|
3
|
-
const REGEX = /url\(\s*['"]?\$\//g
|
|
4
|
-
|
|
5
|
-
// Resolves `$` root aliases in CSS url() references.
|
|
6
|
-
// e.g. url('$/images/foo.png') → url('/absolute/src/images/foo.png')
|
|
7
|
-
export default function cssAliases({root}) {
|
|
8
|
-
const srcDir = join(root, 'src')
|
|
9
|
-
return content => content.replace(REGEX, `url('${srcDir}/`)
|
|
10
|
-
}
|