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

How to keep both extracted CSS and inline CSS? #120

Open
suliskh opened this issue Aug 16, 2018 · 1 comment
Open

How to keep both extracted CSS and inline CSS? #120

suliskh opened this issue Aug 16, 2018 · 1 comment

Comments

@suliskh
Copy link

suliskh commented Aug 16, 2018

I'm building React component library, and I want 2 output bundle:

  1. Bundled React components (.js) which include inline CSS modules
  2. Extracted CSS files, so that I can use component's style in plain HTML nevertheless.

Is that possible to extract CSS , while also keep the inline style in output bundle? Thanks for helping me! Great job by you all~

@simonbrunel
Copy link

Almost the same use case for Chart.js (see chartjs/Chart.js#6015) where we want to be able to provide an option to disable CSS injection for projects with strict CSP policies, which ones should explicitly include the stylesheet instead.

So basically, we need something like:

postcss({
    extract: {
       /**
        * If `true`, the style will be also included JavaScript side. 
        * @default false
        */
       embed: true

       // room for other 'extract' related options ...
       path: 'foobar.css',
       prefix: 'foobar',
       ...
    }
})

@egoist I will be happy to submit a PR if you agree with integrating that feature. In that case, please let me know how you envision the public API for this new behavior.

This was referenced Mar 8, 2020
Vadman97 added a commit to highlight/react that referenced this issue Sep 8, 2022
a little janky, but since we can't have [postcss extract and inject styles in one build](egoist/rollup-plugin-postcss#120), split them out to get both.

Testing: `index.js` and `.es.js` files have inlined css. local also nextjs app works with `highlight.css` import.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants