Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

esbuild import css as a string

I am using vite to build a component library. I use css?inline like this

import otherStyles from './bar.css?inline' // will be available as a string

And use the string to construct stylesheets in the component. see here

Now I made a build script with esbuild. But can't seem to get this inline css to work. Esbuild parses the import but makes an external css.

I know vite (dev env) is based on esbuild, so it should be possible to let esbuild do inline css parsing. Can't find it in the docs, can't find a plugin that does this either.

like image 248
MrKlein Avatar asked Oct 25 '25 14:10

MrKlein


1 Answers

https://github.com/claviska/esbuild-plugin-inline-import

Usage:

import string from 'inline:./path/to/file.ext';

f.e.

import cssCode from 'inline:./path/to/style.css';
like image 174
trusktr Avatar answered Oct 27 '25 05:10

trusktr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!