Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use existing CSS #31

Open
ghost opened this issue Nov 30, 2019 · 10 comments
Open

Use existing CSS #31

ghost opened this issue Nov 30, 2019 · 10 comments
Assignees
Labels
enhancement New feature or request hacktoberfest Hacktoberfest 2020

Comments

@ghost
Copy link

ghost commented Nov 30, 2019

Could you add that it uses existing CSS and we don't need to add extra the csss?

@ghost ghost changed the title Include complete CSS Use existing CSS Dec 5, 2019
@karolsw3
Copy link

Agreed.

@jofftiquez
Copy link
Member

Hello @PortStone can you give more information? What do you mean by existing css? Thanks.

@jofftiquez
Copy link
Member

I'm guessing this means you can pass styles instead of css links right? That would be neat. Will add that to enhancement.

@jofftiquez jofftiquez added the enhancement New feature or request label Feb 12, 2020
@jofftiquez jofftiquez self-assigned this Feb 12, 2020
@jantenuccigsbla
Copy link

@jofftiquez For example i use a CSS loader with webpack and i dont even know the route of the css in my .vue files are in order to pass it to this plugin

@ghost
Copy link
Author

ghost commented Apr 19, 2020

Hello @PortStone can you give more information? What do you mean by existing css? Thanks.

I mean with it that it detects automatically the used CSS and applies it. That means we don't need to add it manually which is a convenient feature.

You can see an example package for Angular here: https://github.com/selemxmn/ngx-print#readme

@jofftiquez jofftiquez added the hacktoberfest Hacktoberfest 2020 label Oct 1, 2020
@robbaker292
Copy link

@jofftiquez For example i use a CSS loader with webpack and i dont even know the route of the css in my .vue files are in order to pass it to this plugin

Am in exactly the same situation

@enjloezz
Copy link

enjloezz commented Jun 5, 2021

Found a temporary (maybe permanent) fix 🥳, basically its grabbing stylesheets from window.document and it checks if its inline css or not. If it is inline css converts it to data schema. In both in development and production mode, it works!

styles: [
    ...new Set(
      [...window.document.styleSheets]
        .map(style => {
          return style.href !== null
            ? style.href
            : `data:text/css;base64,${btoa(
                unescape(
                  encodeURIComponent(
                    [...style.cssRules].map(rule => rule.cssText).join("")
                  )
                )
              )}`;
        })
        .filter(s => s !== null && s !== "data:text/css;base64,")
    )
]

@von-maurus
Copy link

Found a temporary (maybe permanent) fix 🥳, basically its grabbing stylesheets from window.document and it checks if its inline css or not. If it is inline css converts it to data schema. In both in development and production mode, it works!

styles: [
    ...new Set(
      [...window.document.styleSheets]
        .map(style => {
          return style.href !== null
            ? style.href
            : `data:text/css;base64,${btoa(
                unescape(
                  encodeURIComponent(
                    [...style.cssRules].map(rule => rule.cssText).join("")
                  )
                )
              )}`;
        })
        .filter(s => s !== null && s !== "data:text/css;base64,")
    )
]

Wow thats a great solution. I have a question, can you do this but with SCSS?

@NaturalDevCR
Copy link

Found a temporary (maybe permanent) fix 🥳, basically its grabbing stylesheets from window.document and it checks if its inline css or not. If it is inline css converts it to data schema. In both in development and production mode, it works!

styles: [
    ...new Set(
      [...window.document.styleSheets]
        .map(style => {
          return style.href !== null
            ? style.href
            : `data:text/css;base64,${btoa(
                unescape(
                  encodeURIComponent(
                    [...style.cssRules].map(rule => rule.cssText).join("")
                  )
                )
              )}`;
        })
        .filter(s => s !== null && s !== "data:text/css;base64,")
    )
]

Pure gold, not all css styles are catched in quasar, but this is a real start point.

@kyamasam
Copy link

Works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request hacktoberfest Hacktoberfest 2020
Projects
None yet
Development

No branches or pull requests

8 participants