lit-css icon indicating copy to clipboard operation
lit-css copied to clipboard

url(..) calls

Open voidus opened this issue 4 years ago • 7 comments

Hi, thank you so much for this library.

I am using this because I need auto-prefixing on my css, and I'm chaining postcss-loader before this. It's not working right now, and I don't really understand why.

Could we maybe document a known-good webpack config to do this?

voidus avatar May 22 '21 12:05 voidus

Tbf I might just have a messed up config, this seems to work:

        {
          test: /\.lit.css$/,
          use: [
            "lit-css-loader",
            {loader: "postcss-loader", options: postcssLoaderOptions}
          ]
        },

voidus avatar May 22 '21 12:05 voidus

Okay, so I think my real problem is that my url("img/foo.svg") isn't handled. For my usual css, I'm using this:

        {
          test: /\.lit.css$/,
          use: [
            "lit-css-loader",
            {loader: "postcss-loader", options: postcssLoaderOptions}
          ]
        },

But using css-loader or extract-loader breaks lit-css-loader.

Do you have any advice for this? I assume it is a common concern and would be interesting to others, too.

Sorry for thinking aloud in this issue, if you prefer I can gather my thoughts and open a new one.

voidus avatar May 22 '21 13:05 voidus

I appreciate you walking through the issue, thanks

Can you elaborate on what is happening? a small reproduction case with expected output would be good

bennypowers avatar May 23 '21 11:05 bennypowers

I'll look into it when I have a little time, shouldn't be too long.

voidus avatar May 29 '21 15:05 voidus

Hey i have the same issue, I know that the url(...) inside of css literals can be resolved using something like :


import logo from "./src/images/logo.png 

.image { 
   background: url(${ unsafeCss( logo ) });
}

yourFile.d.ts

declare module "*.png" {
    const val : any;
    export default val;
}

When the loader transpile the code to const style = css... ; the url is ommited and the problem is there i think

@MartinEmanuelMaldonado93 can you use the transform config property to transform those calls?

bennypowers avatar Aug 23 '22 18:08 bennypowers

Hey ! has been past few days and I realize that the loader works very well actually, i make the mistake because i misunderstood the webpack url behaviour when compiles. In my webpack.common.js i wrote that the output of my assets be written to the absolute path called "./assets" and in all of my css styles when i required i write url("./assets/myimage.png") and i solve the problem, i don't know if i was clear, but that is the solution i used for my little issue with url's thank you for your answers!