question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for configuring PostCSS for Angular projects

See original GitHub issue

I created new nx/angular project with tailwind and storybook. All works fine, but now I need to add postcss nesting plugin, like postcss-nested or tailwindcss/nesting. I created postcss.config.js in my app and lib directory with following config

module.exports = {
  plugins: [
    'postcss-import',
    'tailwindcss/nesting',
    'tailwindcss',
    'autoprefixer',
  ]
}

Current Behavior

I got “Nested CSS was detected, but CSS nesting has not been configured correctly. Please enable a CSS nesting plugin before Tailwind in your configuration.” message in build log. Seems like nx doesn’t respect postcss.config.js.

Expected Behavior

Should be possibe to add postcss-plugins.

Environment

Node : 16.13.0
   OS   : win32 x64
   yarn : 1.22.17

   nx : 13.8.3
   @nrwl/angular : 13.8.3
   @nrwl/cli : 13.8.3
   @nrwl/cypress : 13.8.3
   @nrwl/detox : undefined
         @angular/cli: 13.2.5
         @angular/compiler-cli: 13.2.4
         @angular/language-service: 13.2.4
         @storybook/angular: 6.4.19

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ambeurcommented, Apr 1, 2022

Yes, i tried, but it looks like postcss.config.js just ignored by builder.

0reactions
leosvelperezcommented, Apr 1, 2022

@zvnt you need to be careful not to overwrite the default Angular CLI webpack configuration for styles. The above will replace the rule configuration for the .css extension. Instead, you could use the function syntax that receives the base webpack configuration and update it with the changes you need:

module.exports = config => {
	// add your logic here updating the config
};

That way, you can obtain the specific rule(s) you want to update from the base configuration and make the needed changes without losing any functionality. You can take a look at some docs/examples updating the webpack config in a similar way to get an idea:

https://indepth.dev/posts/1294/angular-css-modules https://github.com/angular/angular-cli/issues/8427#issuecomment-751520349

Read more comments on GitHub >

github_iconTop Results From Across the Web

Anyone had any luck adding a Post CSS plugin to an Angular ...
Just adding postcss to package.json and having this config file works fine for me. What version are you working with? module.exports = {...
Read more >
Postcss plugins in Angular/cli v11.2 - Stack Overflow
I need to postcss my css with plugin postcss-preset-env for IE11 compatibility (don't ask).
Read more >
PostCSS - a tool for transforming CSS with JavaScript
Transform CSS with the power of JavaScript. Auto-prefixing, future CSS syntaxes, modules, linting and more are possible with hundreds of PostCSS plugins.
Read more >
Compiling SASS and PostCSS with Angular CLI | Codementor
This tutorial will help you configure the build to compile global CSS as well as allow you to use SASS variables declared globally...
Read more >
The [New] State of CSS in Angular | by Emma Twersky
Angular v11.2 added native support for running TailwindCSS ... Create a TailwindCSS configuration file in the workspace or project root
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found