Skip to content
This repository was archived by the owner on Jan 16, 2023. It is now read-only.
This repository was archived by the owner on Jan 16, 2023. It is now read-only.

Support appending to current options object instead of always replacing. #13

@sizeak

Description

@sizeak

Hi,

We're currently using a modified version of this because we don;t want to replace the existing config, we only want to append a new plugin without duplicating the existing CRA postcss config ourselves. Is there any appetite for adding support for this functionality to this plugin itself? I'd be happy to consider putting a PR together if you're interested in adding support.

We're currently using it like this, in case it's useful:

// This function is borrowed & modified from the 'react-app-rewire-postcss' plugin
const rewirePostCss = (config, additionalPlugins) => {
  const filterPostCSSLoader = (array) => array.filter((object) => JSON.stringify(object).includes('postcss-loader'))

  // find any first matching rule that contains postcss-loader
  filterPostCSSLoader(config.module.rules).forEach((rule) => {
    filterPostCSSLoader(rule.oneOf).forEach((oneOf) => {
      filterPostCSSLoader(oneOf.use || oneOf.loader).forEach((use) => {
        // use the latest version of postcss-loader
        use.loader = require.resolve('postcss-loader')
        use.options.plugins = [...use.options.plugins(), ...additionalPlugins]
      })
    })
  })

  return config
}

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions