Replies: 5 comments 5 replies
-
Thanks for creating this discussion! Right now, we support this with our existing plugin API, but only if you use a custom file extension in your source file (ex: As mentioned in another thread, we could allow you to override the default CSS loader, but it just makes it very easy to do so in a way that breaks bundlers since CSS is one of the native web build outputs that we support for bundling. |
Beta Was this translation helpful? Give feedback.
-
I tried writing a plugin-lit-css that extends the lit-sass plugin:
with the intent of providing .lit-css.js files. The first obstacle I ran into was that the function:
by using baseExt instead of extendedExt doesn't let a plugin have .whatever.js extensions which I thought would have been meaningful because I want the file to be treated as .js from the pipeline from this stage on.
gives me null despite my output has my intended key. I am not sure about the meaning of that if. It makes sense to bail out if the output doesn't have the extension required but again since requestedFileExt is just .js that again stops plugin developers from loading .ext.js.
and my example lit-element project works as expected! 🎉 Do you think an approach like this could work? |
Beta Was this translation helpful? Give feedback.
-
@FredKSchott let me know your thoughts about #1909, that would solve the problems I mentioned in my previous post |
Beta Was this translation helpful? Give feedback.
-
I've been struggling with this today and it's by far the biggest pain point I've run into with Snowpack. My use case is custom elements that need to have styles inlined rather than injected into the head. I was hoping to do something like this: import styles from 'my-element.scss'; // using snowpack's sass plugin
class MyElement extends HTMLElement {
constructor() {
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `
<style>${styles}</styles>
...
`;
}
} Unfortunately, the closest I've come to something that works is a hacky plugin that grabs the Sass file, processes it, and injects the resulting CSS with a nasty string replace. Alas, this approach means style changes don't reload the dev server.
After seeing this, I may try to use PostCSS and the |
Beta Was this translation helpful? Give feedback.
-
I think this might be just the best solution of this problem: https://github.com/calebdwilliams/snowpack-lit-scss-plugin |
Beta Was this translation helpful? Give feedback.
-
I am working on a project where we follow this pattern to style our custom elements:
import styles from "./my-element-style.css";
There is a build that generates "my-element-style.css.js" from "my-element-style.scss" using node-sass and wrapping the css text in:
Since this pattern is the suggested from open-wc I thought it would be nice to have a css bundler in snowpack doing the work for us so that we can simply import the sass file.
This would require the bundler to behave differently from what it does at the moment because the javascript proxy should export the css result rather than loading it in the page.
I think it's worth considering this extension because it means that the bundler can support constructable stylesheets and custom elements with shadow dom.
Beta Was this translation helpful? Give feedback.
All reactions