jensljungblad / elemental_components

Simple view components for Rails 5.1+
MIT License
76 stars 5 forks source link

Using components without the asset pipeline #24

Closed fgblomqvist closed 5 years ago

fgblomqvist commented 5 years ago

I tried giving this (seemingly very nice) gem a spin but the component generation command failed since we don't use the asset pipeline (anymore, go webpack!). Are there any other parts of components that are dependent on the asset pipeline or is it just the install command?

In case you're wondering, this is where it failed: https://github.com/jensljungblad/components/blob/master/lib/components/engine.rb#L6

As a side note: what are your plans for this project? Is it considered "finished" and will mostly just receive minimal maintenance, or do you have any immediate plans for new features/more compatibility etc.?

Other than that it looks well-made! :)

jensljungblad commented 5 years ago

Good catch. I've actually also been using webpack mostly for the past few years so I hear you :) Does this mean you've turned off the asset pipeline somehow? As in app.config.assets.paths doesn't exist? I wasn't aware you could do that. I'd be happy to merge a PR that checks for the existence of it before trying to append to it. As far as I know nothing else depends on the asset pipeline. When running the command for generating components you can skip generating css and js files with --skip-css and --skip-js, if you want to place them elsewhere.

As for the future, good question :) I'm currently working in a backend/API team so I'm not personally using it right now. It was developed for and is being used in a production project though. I saw it as a proof of concept, and would be happy to see more people try it out and give feedback. Feature-wise it's more or less what I had in mind, although I was thinking about adding some kind of webpack support. We did see some interesting patterns emerge when using it that could perhaps be introduced as new features at some point. The reason I haven't released it on RubyGems is basically because I have to come up with a name for it... :)

alphabt commented 5 years ago

I would very much love to try this in my current project that uses webpacker. I haven't turned off asset pipeline yet so I hope this works with webpacker out of the box, including compiling .js with es6 in app/components/<component>/*.js

fgblomqvist commented 5 years ago

@jensljungblad Yes, I uninstalled the sprockets gem (and removed any references to the asset pipeline in the rest of the code). The goal was to end up with a Rails project that looks something similar to if you create a new project from scratch with webpacker (that never installs Sprockets I believe). Figured if I don't use it I don't want it in there :) We've run the site for a few months like that now and haven't had any issues. I have a vague memory of trying to install a different Rails gem that ended up not working because it depended on the existence of the asset pipeline (more than just one line like this gem), but I guess (can't remember) we found a different gem that satisfied the goal anyway.

As for running this with webpacker, I'm definitely in the camp that thinks that all assets that belong to a component should be stored with it. I'm not sure off the top of my head how that would work out in the pack file (do you just list each file independently in there or do you have some dynamic logic that does some recursive importing of all relevant assets in the components folder?) since we're currently storing all assets in a webpacker folder (e.g. all SCSS files get imported by module(s)-files then the modules get imported by a main scss file. But yeah please do share any setup/config info you have that could be of use to other webpacker/components explorers :)

Finally, sounds pretty good about the future. I think adding webpacker support (e.g. to docs and making sure the code runs smoothly) would be awesome, but other than that it does seem pretty feature complete (that opinion might change of course once/if we start using it :P)

@iczman sorry not doing any more advanced js compilation for the current project so can't answer your question

EDIT: @jensljungblad yes I can certainly submit a PR, I should be able to get around to it this weekend!

jensljungblad commented 5 years ago

@fgblomqvist I was able to reproduce the issue by creating a Rails app with --skip-sprockets. Opened https://github.com/jensljungblad/components/pull/25. Could you check it out and see if it solves the issue for you?

fgblomqvist commented 5 years ago

@jensljungblad terribly sorry, this slipped my mind the past few days! The fix looks good (essentially what I had in mind to do anyway) and yes I've put a reminder to test it out a little later today. I'll let you know.

fgblomqvist commented 5 years ago

@jensljungblad Just tested it and it works perfectly

jensljungblad commented 5 years ago

@fgblomqvist Perfect! Merged.