How can I load/import a module from a Vite plugin? #15191
Unanswered
NoelDeMartin
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First of all, this is what I'm trying to achieve. I want to have the following in my
index.html
file:And I want it to be compiled to the following (notice the
{{ css(...) }}
part):I don't care that much about the syntax, but I haven't been able to achieve this out of the box. For example, I thought the following would achieve the same result but it didn't:
So I ended up doing my own plugin, using transformIndexHtml, and I could achieve it.
However, now I have an additional problem. This works properly for a plain CSS file, but as soon as I do something that needs some preprocessing, it doesn't work (for example, using
background: url(...)
or importing other css files using postcss's@import
). This happens because I am loading the file using node's plainreadFileSync
, so it isn't using all of Vite's processing pipeline.How can I load a file's content, from a plugin's
transformIndexHtml
hook, including all of Vite's preprocessing?Beta Was this translation helpful? Give feedback.
All reactions