-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from gwleuverink/feature/css-loader
Feature/css loader
- Loading branch information
Showing
30 changed files
with
712 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
nav_order: 7 | ||
nav_order: 8 | ||
title: Caveats | ||
image: "/assets/social-square.png" | ||
--- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
--- | ||
nav_order: 5 | ||
title: CSS loading | ||
image: "/assets/social-square.png" | ||
--- | ||
|
||
## CSS Loading | ||
|
||
**Beta** | ||
|
||
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 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. | ||
|
||
```html | ||
<x-import module="tippy.js" as="tippy" /> | ||
<x-import module="tippy.js/dist/tippy.css" /> | ||
``` | ||
|
||
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. | ||
|
||
That being said; We do recommend installing Lightning CSS in your project. | ||
|
||
```bash | ||
npm install lightningcss --save-dev | ||
``` | ||
|
||
### Sass | ||
|
||
[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. | ||
|
||
```bash | ||
npm install lightningcss --save-dev | ||
``` | ||
|
||
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. | ||
|
||
### Local CSS loading | ||
|
||
This works similar to [local modules](https://laravel-bundle.dev/local-modules.html). Simply add a new path alias to your `jsconfig.json` file. | ||
|
||
```json | ||
{ | ||
"compilerOptions": { | ||
"paths": { | ||
"~/css": ["./resources/css/*"] | ||
} | ||
} | ||
} | ||
``` | ||
|
||
Now you can load css from your resources directory. | ||
|
||
```html | ||
<x-import module="css/foo-bar.css" /> | ||
``` | ||
|
||
### Browser targeting | ||
|
||
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. | ||
|
||
You can define what browsers to target using your `package.json` file: | ||
|
||
```json | ||
{ | ||
"browserslist": ["last 2 versions", ">= 1%", "IE 11"] | ||
} | ||
``` | ||
|
||
<br/> | ||
|
||
{: .note } | ||
|
||
> Bundle currently only supports browserslist using your `package.json` file. A dedicated `.browserslistrc` is not suppported at this time. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
nav_order: 6 | ||
nav_order: 7 | ||
has_children: true | ||
title: Integration examples | ||
image: "/assets/social-square.png" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
nav_order: 5 | ||
nav_order: 6 | ||
title: Production builds | ||
image: "/assets/social-square.png" | ||
--- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// NOTE: we don't have to check if Bun is installed sinsce this script is invoked with the Bun runtime | ||
|
||
import { parseArgs } from "util"; | ||
import { exit } from "./utils/dump"; | ||
import cssLoader from "./plugins/css-loader"; | ||
|
||
const options = parseArgs({ | ||
args: Bun.argv, | ||
strict: true, | ||
allowPositionals: true, | ||
|
||
options: { | ||
entrypoint: { | ||
type: "string", | ||
}, | ||
|
||
inputPath: { | ||
type: "string", | ||
}, | ||
|
||
outputPath: { | ||
type: "string", | ||
}, | ||
|
||
sourcemaps: { | ||
type: "boolean", | ||
}, | ||
|
||
minify: { | ||
type: "boolean", | ||
}, | ||
}, | ||
}).values; | ||
|
||
const result = await Bun.build({ | ||
entrypoints: [options.entrypoint], | ||
publicPath: options.outputPath, | ||
outdir: options.outputPath, | ||
root: options.inputPath, | ||
minify: options.minify, | ||
|
||
sourcemap: options.sourcemaps ? "external" : "none", | ||
|
||
naming: { | ||
entry: "[dir]/[name].[ext]", | ||
chunk: "chunks/[name]-[hash].[ext]", // Not in use without --splitting | ||
asset: "assets/[name]-[hash].[ext]", // Not in use without --splitting | ||
}, | ||
|
||
target: "browser", | ||
format: "esm", | ||
|
||
plugins: [ | ||
cssLoader({ | ||
minify: Boolean(options.minify), | ||
sourcemaps: Boolean(options.sourcemaps), | ||
}), | ||
], | ||
}); | ||
|
||
if (!result.success) { | ||
// for (const message of result.logs) { | ||
// console.error(message); | ||
// } | ||
// process.exit(1); | ||
|
||
// TODO: needs to be reworked | ||
exit('build-failed', '', result.logs.map(log => log.message)) | ||
} |
Oops, something went wrong.