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

Unable to get postcss plugins working #34

Open
janniks opened this issue Nov 30, 2023 · 4 comments
Open

Unable to get postcss plugins working #34

janniks opened this issue Nov 30, 2023 · 4 comments

Comments

@janniks
Copy link

janniks commented Nov 30, 2023

I'm trying to get postcss working, but it seems the examples and docs aren't working for me.

Project to reproduce here: hirosystems/connect#346

yarn
npx lerna run build --scope @stacks/connect-ui

This builds the stencil component in the monorepo. Inspecting the file at packages/connect-ui/dist/cjs/connect-modal.cjs.entry.js shows the modalCss is NOT renamed. Anything I'm missing?

Also, removing tailwindHMR removes CSS completely -- not sure if that is intended 🤔

Thanks for the project, thanks for the help 🙏

@janniks
Copy link
Author

janniks commented Nov 30, 2023

I've tried different postcss strategies (as config file or config object) -- No change
I've tried with and without HMR -- CSS only works with HMR (but doesn't rename)

@Poimen
Copy link
Owner

Poimen commented Dec 4, 2023

Hi @janniks

It's a bit of deep PR you've linked there and difficult to know what the end result you're expecting here.

I'll try pull your branch this evening and give it a try. Could you detail exactly what you are expecting to happen? (like "I have class someclass, I expect this to be renamed to moz-someclass")

Off the top of my head, what you could try is move the configuration out of the default options and use the tailwind({}) to set the postcss options.

@Poimen
Copy link
Owner

Poimen commented Dec 16, 2023

Hi @janniks

I couldn't get your repo to run properly, some sort of missing deps. But I did manage to get lerna to build the component.

From what I can tell, it is working as expected.

The simplest way of testing this is to set the configuration to remove autoprefixer from the configuration:

setPluginConfigurationDefaults({
  ...PluginOpts.DEFAULT,
  enableDebug: true,
  stripComments: true,
  useAutoPrefixer: false,  // <-- important, disable the internal autoprefixer
  tailwindConf,
  postcss: {
    plugins: [
      tailwindcss(),
      // autoprefixer(),   // <-- no autoprefixer here
    ]
  }
});

Add the following class to the component and the css:

.example {
  display: grid;
  transition: all .5s;
  user-select: none;
  background: linear-gradient(to bottom, white, black);
}

Then build the site - stash the result.

Add autoprefixer back into the mix:

setPluginConfigurationDefaults({
  ...PluginOpts.DEFAULT,
  enableDebug: true,
  stripComments: true,
  useAutoPrefixer: false,  // <--- important, still make the internal autoprefixer disabled
  tailwindConf,
  postcss: {
    plugins: [
      tailwindcss(),
      autoprefixer(),
    ]
  }
});

Build the site again, and compare the outputs.

The .example should show differences with the prefixing.

In my setup, without autoprefixer:

.example {
    background: linear-gradient(180deg, #fff, #000);
    display: grid;
    transition: all .5s;
    user-select: none
}

(as expected, no prefixing) - with autoprefixer:

.example {
    background: linear-gradient(180deg, #fff, #000);
    display: grid;
    transition: all .5s;
    -webkit-user-select: none;
    -moz-user-select: none;
    user-select: none
}

(as epected, prefixed user-select).

I would conclude that the postcss configuration is working as expected.

If you could give more details on what you are expecting to happen.

If you are expecting that modalCss is going to be renamed, then this would not happen because of the way StencilJS composes the data - modalCss is the object for creating the web component.

As example:

const modalCss = " ... some log css string ...";

const Modal = class {} // Actual component class for the web component

Modal.style = modalCss;  // <-- this style is used to component style block as memory serves

Hence, the modalCss cannot be a shorter name, as this is part of the framework. Is this what you were expecting?

@janniks
Copy link
Author

janniks commented Dec 16, 2023

Thanks so much for investigating. 🙏🏻

I was mainly looking at the content of the modalCss string.

I'll try again. I'll set up a codesandbox to reproduce, if possible.

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