Skip to content

Development: Inline CSS & Manifest file #406

Answered by ElMassimo
zangab asked this question in Q&A
Discussion options

You must be logged in to vote

Hi there!

Vite also provides a manifest, which is implicitly read from when using helpers such as vite_stylesheet_tag when the dev server is not running or in production.

If you need to inline styles, you could do so without having to build your files, by using a helper to detect if the Vite dev server is running and simply fetching the file in CSS format (it will be precompiled on the fly), or reading the file locally when the build has already run:

  def vite_inline_style(path)
    path = ViteRuby.instance.manifest.path_for(path)

    css = if ViteRuby.instance.dev_server_running?
      uri = URI("#{ViteRuby.config.origin}#{path}")
      Net::HTTP.get(uri, {"Accept" => "text/css"})
    e…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@zangab
Comment options

@ElMassimo
Comment options

@ermolaev
Comment options

Answer selected by zangab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants