Skip to content

Commit 4171887

Browse files
authored
Merge pull request #13 from gwleuverink/feature/css-loader
Feature/css loader
2 parents 0e62bed + 9deb0ca commit 4171887

30 files changed

Lines changed: 712 additions & 101 deletions

.github/workflows/browser-tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
name: browser-tests
22

33
on:
4+
pull_request:
5+
branches: [development, main]
46
workflow_run:
57
workflows: [tests]
68
types: [completed]

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@
7878
"cd ./workbench && npm ci",
7979
"ln -sf $PWD/workbench/jsconfig.json ./vendor/orchestra/testbench-core/laravel",
8080
"ln -sf $PWD/workbench/node_modules/ ./vendor/orchestra/testbench-core/laravel",
81-
"ln -sf $PWD/workbench/resources/js/ ./vendor/orchestra/testbench-core/laravel/resources"
81+
"ln -sf $PWD/workbench/resources/js/ ./vendor/orchestra/testbench-core/laravel/resources",
82+
"ln -sf $PWD/workbench/resources/css/ ./vendor/orchestra/testbench-core/laravel/resources"
8283
],
8384

8485
"serve": [

config/bundle.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
| and disable this on your local development environment.
1212
|
1313
*/
14-
'caching_enabled' => env('BUNDLE_CACHING_ENABLED', app()->isProduction()),
14+
'caching' => env('BUNDLE_CACHING', true),
1515

1616
/*
1717
|--------------------------------------------------------------------------
@@ -47,7 +47,7 @@
4747
| won't impact performance when your imports are build for prod.
4848
|
4949
*/
50-
'sourcemaps_enabled' => env('BUNDLE_SOURCEMAPS_ENABLED', false),
50+
'sourcemaps' => env('BUNDLE_SOURCEMAPS', false),
5151

5252
/*
5353
|--------------------------------------------------------------------------

docs/advanced-usage.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ All code is minified by default. This can make issues harder to debug at times.
9595

9696
## Sourcemaps
9797

98-
Sourcemaps are disabled by default. You may enable this by setting `BUNDLE_SOURCEMAPS_ENABLED` to true in your env file or by publishing and updating the bundle config.
98+
Sourcemaps are disabled by default. You may enable this by setting `BUNDLE_SOURCEMAPS` to true in your env file or by publishing and updating the bundle config.
9999

100100
Sourcemaps will be generated in a separate file so this won't affect performance for the end user.
101101

102102
{: .note }
103103

104-
> If your project stored previously bundled files you need to run the [bundle:clear](https://laravel-bundle.dev/advanced-usage.html#artisan-bundleclear) command
104+
> If your project stored previously bundled files you need to run the [bundle:clear](https://laravel-bundle.dev/advanced-usage.html#artisan-bundleclear) command after enabling/disabling this feature.
105105
106106
## Cache-Control headers
107107

@@ -148,9 +148,3 @@ BundleManager::fake();
148148
```
149149

150150
When you'd like to use Dusk for browser testing you need to run Bundle in order for your tests not to blow up. Simply don't fake the BundleManager in your DuskTestCase.
151-
152-
## CSS Loader
153-
154-
Bun doesn't ship with a css loader. They have it on [the roadmap](https://github.com/oven-sh/bun/issues/159){:target="\_blank"} but no release date is known at this time. We plan to support css loading out-of-the-box as soon as Bun does!
155-
156-
We'd like to experiment with Bun plugin support soon. If that is released before Bun's builtin css loader does, it might be possible to write your own plugin to achieve this.

docs/caveats.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
nav_order: 7
2+
nav_order: 8
33
title: Caveats
44
image: "/assets/social-square.png"
55
---

docs/css-loading.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
nav_order: 5
3+
title: CSS loading
4+
image: "/assets/social-square.png"
5+
---
6+
7+
## CSS Loading
8+
9+
**Beta**
10+
11+
Bun doesn't ship with a CSS loader. They have it on [the roadmap](https://github.com/oven-sh/bun/issues/159){:target="\_blank"} but no release date is known at this time.
12+
13+
We provide a custom CSS loader plugin that just works™. Built on top of [Lightning CSS](https://lightningcss.dev/). Just use the `x-import` directive to load a css file directly. Bundle transpiles them and injects it on your page with zero effort.
14+
15+
```html
16+
<x-import module="tippy.js" as="tippy" />
17+
<x-import module="tippy.js/dist/tippy.css" />
18+
```
19+
20+
Because we use Bun as a runtime when processing your files there is no need to install Lightning CSS as a dependency. When Bun encounters a import that is not installed it will fall back to it's on internal [module resolution algorithm](https://bun.sh/docs/runtime/autoimport) & install the dependency on the fly.
21+
22+
That being said; We do recommend installing Lightning CSS in your project.
23+
24+
```bash
25+
npm install lightningcss --save-dev
26+
```
27+
28+
### Sass
29+
30+
[Sass](https://sass-lang.com/) is supported out of the box. Just like with Lightning CSS you don't have to install Sass as a dependency, but it is recommended.
31+
32+
```bash
33+
npm install lightningcss --save-dev
34+
```
35+
36+
Note that compiled Sass is processed with LightningCSS afterwards, so if you plan on only processing scss files it is recommended to install both Lightning CSS & Sass.
37+
38+
### Local CSS loading
39+
40+
This works similar to [local modules](https://laravel-bundle.dev/local-modules.html). Simply add a new path alias to your `jsconfig.json` file.
41+
42+
```json
43+
{
44+
"compilerOptions": {
45+
"paths": {
46+
"~/css": ["./resources/css/*"]
47+
}
48+
}
49+
}
50+
```
51+
52+
Now you can load css from your resources directory.
53+
54+
```html
55+
<x-import module="css/foo-bar.css" />
56+
```
57+
58+
### Browser targeting
59+
60+
Bundle automatically compiles many modern CSS syntax features to more compatible output that is supported in your target browsers. This includes some features that are not supported by browsers yet, like nested selectors & media queries, without using a preprocessor like Sass. [Check here](https://lightningcss.dev/transpilation.html#syntax-lowering) for the list of the many cool new syntaxes Lightning CSS supports.
61+
62+
You can define what browsers to target using your `package.json` file:
63+
64+
```json
65+
{
66+
"browserslist": ["last 2 versions", ">= 1%", "IE 11"]
67+
}
68+
```
69+
70+
<br/>
71+
72+
{: .note }
73+
74+
> Bundle currently only supports browserslist using your `package.json` file. A dedicated `.browserslistrc` is not suppported at this time.

docs/integrations/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
nav_order: 6
2+
nav_order: 7
33
has_children: true
44
title: Integration examples
55
image: "/assets/social-square.png"

docs/production-builds.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
nav_order: 5
2+
nav_order: 6
33
title: Production builds
44
image: "/assets/social-square.png"
55
---

docs/roadmap.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
nav_order: 8
2+
nav_order: 9
33
title: Roadmap
44
image: "/assets/social-square.png"
55
---
@@ -8,7 +8,15 @@ image: "/assets/social-square.png"
88

99
Bundle is under active development. If you feel there are features missing or you've got a great idea that's not on on the roadmap please [open a discussion](https://github.com/gwleuverink/bundle/discussions/categories/ideas){:target="\_blank"} on GitHub.
1010

11-
## CSS loader
11+
## ✅ Injecting Bundle's core on every page
12+
13+
**_Added in [v0.1.3](https://github.com/gwleuverink/bundle/releases/tag/v0.1.3)_**
14+
15+
This will reduce every import's size slightly. But more importantly; it will greatly decrease the chance of unexpected behaviour caused by race conditions, since the Bundle's core is available on pageload.
16+
17+
## ✅ CSS loader
18+
19+
**_Added in [v0.1.4](https://github.com/gwleuverink/bundle/releases/tag/v0.1.4)_**
1220

1321
Bun doesn't ship with a CSS loader. They have it on [the roadmap](https://github.com/oven-sh/bun/issues/159){:target="\_blank"} but no release date is known at this time. We plan to support CSS loading out-of-the-box as soon as Bun does!
1422

@@ -98,12 +106,6 @@ It would be incredible if this object could be forwarded to Alpine directly like
98106
</div>
99107
```
100108

101-
## ✅ Injecting Bundle's core on every page
102-
103-
**_Added in [v0.1.3](https://github.com/gwleuverink/bundle/releases/tag/v0.1.3)_**
104-
105-
This will reduce every import's size slightly. But more importantly; it will greatly decrease the chance of unexpected behaviour caused by race conditions, since the Bundle's core is available on pageload.
106-
107109
## Optionally assigning a import to the window scope
108110

109111
It could be convenient to provide an api to assign imports to a window variable by use of a prop. This idea is still settling in so might change.

phpunit.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,18 @@
44
bootstrap="vendor/autoload.php"
55
colors="true"
66
>
7+
<php>
8+
<env name="BUNDLE_MINIFY" value="true" />
9+
<env name="BUNDLE_CACHING" value="false" />
10+
<env name="BUNDLE_SOURCEMAPS" value="false" />
11+
</php>
12+
713
<testsuites>
814
<testsuite name="Test Suite">
915
<directory suffix="Test.php">./tests</directory>
1016
</testsuite>
1117
</testsuites>
18+
1219
<source>
1320
<include>
1421
<directory suffix=".php">./app</directory>

0 commit comments

Comments
 (0)