Skip to content

Include js-based postcss config #105

Closed
@vz-tl

Description

@vz-tl
Contributor

Please add support for including postcss-config.js instead of just JSON based configs, as the drawback with JSON format is, they cannot be altered dynamically.

In my current setup, certain postcss plugin parameters configured in the js-based config are set conditionally depending on running a dev or prod build, but that's not possible by having to use JSON based configs.

I temporarily worked around that by monkey-patching the plugin sources as followed:

-- a/node_modules/@nx/angular-rspack/dist/lib/utils/postcss-configuration.js
+++ b/node_modules/@nx/angular-rspack/dist/lib/utils/postcss-configuration.js
@@ -15,6 +15,7 @@ const node_path_1 = require("node:path");
 const postcssConfigurationFiles = [
     'postcss.config.json',
     '.postcssrc.json',
+    'postcss.config.js',
 ];
 const tailwindConfigFiles = [
     'tailwind.config.js',
@@ -51,7 +52,7 @@ async function loadPostcssConfiguration(searchDirectories) {
     if (!configPath) {
         return undefined;
     }
-    const raw = await readPostcssConfiguration(configPath);
+    const raw = configPath.endsWith('.js') ? require(configPath) : await readPostcssConfiguration(configPath);
     // If no plugins are defined, consider it equivalent to no configuration
     if (!raw.plugins || typeof raw.plugins !== 'object') {
         return undefined;

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @Coly010@vz-tl

      Issue actions

        Include js-based postcss config · Issue #105 · nrwl/angular-rspack