Coder Social home page Coder Social logo

Comments (4)

ElMassimo avatar ElMassimo commented on May 23, 2024 1

@Jonic If you are referring to Sidecar Assets, it should be possible to do something similar in Vite Ruby.

Instead of require.context you would use a globEager import.

Here's an example using globEager to register all Stimulus controllers.

If you are referencing individual assets from Rails views or partials directly, then it's not going to be a drop-in replacement, but if you are combining the components in a single "pack" it should be easier.

would I be unable to reference the images with vite_asset_path since they're not in the entrypoints directory?

No. When using Vite.js you would ideally import the images in the relevant component and use their source in the component itself.

from vite_ruby.

ElMassimo avatar ElMassimo commented on May 23, 2024

Hi Jonic!

The Troubleshooting guide is indeed misleading in this scenario, I will update it accordingly.

To answer your question, all tag helpers including vite_asset_path can only reference files in the entrypoints directory.

If you are only referencing images from any JS or CSS processed by Vite, you would be able to import them without placing them under entrypoints.

from vite_ruby.

ElMassimo avatar ElMassimo commented on May 23, 2024

Updated the docs, removed the reference to an unrelated older issue in Vite, and clarified where the assets are located in the Rails vite_asset_path example.

Thanks!

from vite_ruby.

Jonic avatar Jonic commented on May 23, 2024

@ElMassimo Thanks for the clarification - it's much clearer now! I was hoping to use Github's ViewComponent gem, keeping each component's assets with the Ruby class and erb template, for example:

app/components/header_component
  ./header.rb
  ./header.erb
  ./header.scss
  ./header.js
  ./images/logo.svg

I understand that I'd have to import the Sass and JS from an entrypoint, and that these files can in turn load images, but would I be unable to reference the images with vite_asset_path since they're not in the entrypoints directory? I'm still trying to figure out if Vite Ruby could be an easy-ish drop-in replacement for our current setup, or if it would involve significant reshuffling and a massive PR to make it all happen. Apologies if I'm being dense!

from vite_ruby.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.