From 550d7e50a952a146764d4088b0d154dd840496f5 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Wed, 25 Jan 2023 16:34:46 -0500 Subject: [PATCH] docs: You can now include CSS manually if it's a top-level entry in your `vite.config.js` (rather than being imported into your JavaScript) via `craft.vite.asset("src/css/app.css")` ([#31](https://github.com/nystudio107/craft-vite/issues/31)) --- docs/docs/index.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/docs/docs/index.md b/docs/docs/index.md index c42dcd6..7ac0293 100755 --- a/docs/docs/index.md +++ b/docs/docs/index.md @@ -714,6 +714,32 @@ If you need to access assets that are in the `public/` directory from Twig, ther {{ craft.vite.asset("src/images/quote-open.svg", true) }} ``` +#### Using `craft.vite.asset` with CSS + +If you are using Vite 3.x or later, you can also use `craft.vite.asset` to manually include CSS that is a top-level entry in your `vite.config.js` (rather than being imported into your JavaScript): + +```twig + {{ craft.vite.asset("src/css/app.css") }} +``` + +This assumes your `vite.config.js` looks something like this: + +```js + build: { + emptyOutDir: true, + manifest: true, + rollupOptions: { + input: { + app: 'src/js/app.ts', + css: 'src/css/app.css' + }, + output: { + sourcemap: true + }, + } + }, +``` + ### The `.inline()` function The Vite plugin also includes a `.inline()` function that inlines the contents of a local file (via path) or remote