Give more love to developers from SDC experience

Created on 8 August 2023, over 1 year ago
Updated 18 June 2024, 5 months ago

Problem/Motivation

Found 2 problems, so describing feature request:

1. SDC allows to define components only in `components/` folder in theme.

Drupal by default can scan twig templates located in theme in `templates/` folder. If we are following this logic - all twig files should be placed in `templates/` folder in theme (no matter if it's component or not). In the same time i understand - components are something "bigger" than just twig files: it can contain also css, js, yml, etc files (so not clear why they should be stored in `templates` folder).

On the other hand we have several contrib initiatives, like UI Patterns and other initiatives, which are saying us to store patters, components, whatever else in `templates` folder.

Now, just imagine real commerce project, where several techniques are used: for example SDC + UI Patterns + something else to deliver components in drupal (this is where we are, it's real case!) - so it will be very annoying why a part of components living in `components/` folder, while other components living in `templates/` folder.

+ imagine if we have smth like storybook on the project -> managing/grouping of components becomes unclear.

What i want to say - is that maybe SDC should allow to store components also in `templates` folder. It's a tiny change from my pov, which will not damage performance, which will not make understanding of SDC harder. In the same time it becomes possible to use several approaches in one theme.

2. Another problem related to auto-call of `my-component.js` and `my-component.css` files. Correct me if i'm wrong, but if i have `my-component.js` file let's say empty -> it will be attached in drupal anyway with no ability to not attach this file. The only way is to just remove such file. At least i didn't find docs which allows me to not attach my assets via yml file, only override something.

What i want to say is next: just imagine component generator. We have (i almost sure) many different component generators in 2023, some of them are unpopular, not so smart, "local" in companies, etc. As a front-end developer what i'm expecting from component generator? I'm expecting yml file, css, (maybe even postcss file), js, (maybe even my-component.source.js file and its compiled version let's say my-component.js), also twig. This is must have for component generator, isn't it ?

Now, for example i don't need js file at this moment. Some generators are pretty smart, so they will ask me in the middle of generation process if i need js file or not. But as a developer - i never know if i will need my js file later or not. And if component generator didn't generate js file for me and i will need in in future, how to handle this process? I mean.. of course you can just manually create such file, put behaviors in there and write custom js, but it is annoying process for me. Better (sometimes at least) to have js file always. Maybe content (aka. js-template, generated by component generator) in there will be commented, but there will be already "prepared" code to start writing custom js. So some component generators can generate js file but with commented code inside (commented code already includes file info, drupal behavior with component name, like `Drupal.behaviors.myComponent`. And if i will need my js later - what i have to do is to just uncomment my js code and i'm ready to write custom js scripts in already prepared drupal behavior.

Sooo... if i have js file with commented code inside (or css file, doesn't matter) - i don't want to attach it in Drupal (but seems with SDC it's impossible right now).

I also thinking that we'd better avoid auto-attaching css and js at all. If you need something -> use yml, attach whatever you need

✨ Feature request
Status

Active

Version

11.0 πŸ”₯

Component
single-directory componentsΒ  β†’

Last updated about 22 hours ago

Created by

πŸ‡·πŸ‡ΊRussia kostyashupenko Omsk

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024