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

Support PostCSS #240

Closed
2 of 3 tasks
nvh95 opened this issue Aug 18, 2022 · 1 comment
Closed
2 of 3 tasks

Support PostCSS #240

nvh95 opened this issue Aug 18, 2022 · 1 comment
Assignees
Labels
feature request Request a new feature
Milestone

Comments

@nvh95
Copy link
Owner

nvh95 commented Aug 18, 2022

Is your feature request related to a problem? Please describe.

Now, jest-preview is currently supporting TailwindCSS (#100). It does use postcss but only for tailwindcss

const postcss = require("postcss");
const cssSrc = ${JSON.stringify(src)};
postcss([require("tailwindcss")(), require("autoprefixer")()])
.process(cssSrc, { from: ${JSON.stringify(filename)} })
.then((result) => {
const style = document.createElement("style");
style.type = "text/css";
style.appendChild(document.createTextNode(result.css.replace(/\\\\/g, '')));
document.head.appendChild(style);
});
`,

By supporting PostCSS natively, it can solve a number of issues

Describe the solution you'd like

Current logic

  • If a file has TailwindCSS syntax => process it with PostCSS (with tailwindcss plugins).

Desured logic

  • Detect if a project uses PostCSS => process with PostCSS and corresponding configuration.

Describe how should jest-preview implements this feature

  1. To detect if a project uses PostCSS, we can use postcss-load-config
  1. Process CSS file with above config

The pseudocode will look like this:

// src/transform.ts
export function processCss(src: string, filename: string) {
  // Pre-process file with Sass/ Less/ Stylus
  ...
  // Check if project use PostCSS
  const { plugins, options } = postcssrc.sync(ctx)
  const { css } = postcss(plugins).process(src, options)
  injectToHead(css)

  // Else, likely raw CSS, just inject to head directly
  injectToHead(src)
}

Describe alternatives you've considered

None

Additional context

Will provide if there any in the future

@nvh95 nvh95 added the feature request Request a new feature label Aug 18, 2022
@nvh95 nvh95 added this to the 0.3.0 milestone Aug 18, 2022
@nvh95 nvh95 self-assigned this Aug 18, 2022
@nvh95 nvh95 mentioned this issue Aug 20, 2022
4 tasks
@nvh95
Copy link
Owner Author

nvh95 commented Aug 22, 2022

Implemented in #241

@nvh95 nvh95 closed this as completed Aug 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Request a new feature
Projects
None yet
Development

No branches or pull requests

1 participant