Giter Site home page Giter Site logo

How to integrate PostCSS about microsite HOT 6 CLOSED

natemoo-re avatar natemoo-re commented on April 28, 2024
How to integrate PostCSS

from microsite.

Comments (6)

natemoo-re avatar natemoo-re commented on April 28, 2024 4

I definitely want this to be super simple out of the box! In this case I think it might be because Microsite uses "type": "module" in a project's package.json file. PostCSS only picks up on CJS, so try postcss.config.cjs?

Microsite automatically uses the official Snowpack plugin if it picks up on a PostCSS configuration file (via cosmiconfig). Custom snowpack.config.js files is something I want to add for the next release, though.

from microsite.

natemoo-re avatar natemoo-re commented on April 28, 2024 4

I added a working Tailwind example in cadd0a5. Since Tailwind doesn't currently support a tailwind.config.cjs file (I'm planning to make a PR to fix this), you need to actually require the config from postcss.config.cjs and then pass it to the tailwindcss plugin. Not ideal, but it works for now. Once Tailwind supports a .cjs config file this should be much easier.

from microsite.

natemoo-re avatar natemoo-re commented on April 28, 2024 1

I'll definitely update the docs to mention this! Certainly on the bleeding edge of ESM in Node here.

As for Tailwind and PurgeCSS, I'll see if I can get it working and add an example to the project. I have a suspicion it's a hidden side-effect of the multi-stage build that happens in the background.

from microsite.

pterblgh avatar pterblgh commented on April 28, 2024

I can confirm that PostCSS works completely fine if someone renames the default postcss.config.js file to postcss.config.cjs - actually the same goes to tailwind.config.js as well.

There's one thing I haven't found a solution yet. Tailwind CSS provides a way to remove unused CSS classes from the final built CSS using purge-css under the hood. Even if providing NODE_ENV=production option for the npm run build command for some reason PostCSS/Tailwind does not pick up this config thus at the end of the process the CSS file emitted is not "tree-shaked" and not even minified - which should be the default behaviour for Tailwind if NODE_ENV is set to production as far as I know.

This is how my postcss.config.cjs file looks like:

module.exports = {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  },
};

And here is what's in the tailwind.config.cjs file:

module.exports = {
 // This should instruct Tailwind to purge CSS based on these files
  purge: ['./src/**/*.tsx'],
  darkMode: false, // or 'media' or 'class'
  theme: {
    extend: {},
  },
  variants: {
    extend: {},
  },
  plugins: [],
};

Will take another look later, my guess is that NODE_ENV=production does not propagate correctly from the command line to Tailwind through @snowpack/plugin-postcss - but again, this is just a guess.

from microsite.

equinusocio avatar equinusocio commented on April 28, 2024

I can confirm, using postcss.config.cjs instead of postcss.config.js works as expected. I think this should be mentioned inside the doc because using .cjs it's not so popular yet.

from microsite.

natemoo-re avatar natemoo-re commented on April 28, 2024

Added a note about PostCSS using .cjs in f369f5e.

from microsite.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.