Closed braughtg closed 1 week ago
The above description does not seem to be quite accurate. For example, the SubmitResetButtons
component has its own <style scoped>
blog and is used in multiple entry points but is not packaged into its own .css file. The result is that the buttons are not actually styled using the <style scoped>
styles when the buttons are rendered in an entry point. This is something that will need to be better understood. This will relate to #219 also.
Here are a few links that might be useful in tracking down a solution to this:
This seems too simple but maybe ...
These two look pretty good:
Some others...
Using cssCodeSplit: false
in the vite build
will not work. This adds the css to the .js
file, but that file is pulled into the drupal page in the body so the css is not recognized. Similarly none of the injected styles will work. either.
Seems like the only path forward is to ensure that every component that has <style scoped>
gets a .css
file generated for it and that that file is included in the *.libraries.yml
file for the drupal module.
May need to build in lib
mode and include an entry point for each entry point and each component and each library. Possibly adapt the following:
build: {
lib: {
format: ['es'],
entry: {
index: 'src/index.ts',
button: 'src/components/button/index.ts',
select: 'src/components/select/index.ts',
},
}
rollupOptions: {
output: {
// Put chunk files at <output>/chunks
chunkFileNames: 'chunks/[name].[hash].js',
// Put chunk styles at <output>/assets
assetFileNames: 'assets/[name][extname]',
entryFileNames: '[name].js',
},
},
}
This would require generating the entry
piece programmatically from the component
, entrypoints
and libraries
directories.
This doesn't seem to be working out well.
Also noticed that the build for fd2
places some bits of code and css into uiUtil.js
and uiUtil.css
. These seem to be bits taken from some of the components. It is not at all clear why this code is going into those files rather than into a file associated with the component. Maybe figuring that out will present an answer?
Also noticed that the build for
fd2
places some bits of code and css intouiUtil.js
anduiUtil.css
. These seem to be bits taken from some of the components. It is not at all clear why this code is going into those files rather than into a file associated with the component. Maybe figuring that out will present an answer?
If the uiUtil.css
file is added to the Drupal libraries (*.libraries.yml
) then the styling that was moved there is applied.
This works, but is unsatisfying because the *.libraries.yml
file will have to be customized for each entry point because it may need a .css
that was separated out (e.g. CropSelector
or SoilDisturbance
) or not.
A few thoughts here:
*.libraries.css
- Maybe we can get all the css into a single flie and then put that in
*.libraries.css
Setting build.cssCodeSplit: false
in the vite.config.js
file causes all of the css to be placed into style/style.css
.
So if that file is then included in the *libraries.yml
for all of the entry points things should be good to go.
Proposed Solution:
vite.config.js
files (fd2, examples, school) to
build.cssCodeSplit: false
style/style.css
file to be built with the css for the whole module.build.exclude
since it is not having any effect.assetFileNames logic with
assetFileNames: '[name]/[name].[ext]',`*.libraries.yml
files (fd2, examples, school) to
style/style.css
to the entry points as component
libraries.yml
to attach just the style/style.css
file as component
to future entry points.
When multiple entry points in a module use a component that has a
<style scoped>
block Vite splits the CSS into its own file. This then requires that Drupal be told about that file in the<module>.libraries.yml
file in thecss:
section. Note that if only one entry point in the module uses the component then the css is bundled into that entry point's css and everything is fine without adding it to thelibraries.yml
file. That said, there seems to be no harm in including the component's.css
file in thelibraries.yml
even if only one component uses it (though there may be errors getting logged somewhere in drupal???).Need to develop a consistent way of handling this and documenting it so that when it goes wrong (and I'm sure it will) there is at least something to refer to.
Also related, it appears that all of the
.css
in the<module>.libraries.yml
file can go under thecomponent:
heading instead of including one under thetheme:
heading. Should probably check on what the difference is there. If this is the way to go then the templates for the entry point should also be updated (related to #189)This should all be fixed retroactively for all of the entry points thus far.