export default function getPostcssOpts()

in packages/shared-config/src/getPostcssOpts.ts [16:67]


export default function getPostcssOpts({
  rootDir,
  userPostcssOptions,
  enableRpx2Vw,
}: {
  rootDir: string;
  userPostcssOptions: Options['postcssOptions'];
  enableRpx2Vw: boolean;
}): Options['postcssOptions'] & { implementation?: typeof postcss } {
  const postcssConfigPath = path.join(rootDir, 'postcss.config.js');
  const defaultPostcssOpts = {
    // lock postcss version
    implementation: postcss,
  };
  if (fs.existsSync(postcssConfigPath)) {
    return defaultPostcssOpts;
  } else {
    const defaultPostcssPlugins = [
      ['@ice/bundles/compiled/postcss-nested'],
      ['@ice/bundles/compiled/postcss-preset-env', {
        // Without any configuration options, PostCSS Preset Env enables Stage 2 features.
        stage: 3,
        autoprefixer: {
          // Disable legacy flexbox support
          flexbox: 'no-2009',
        },
        features: {
          'custom-properties': false,
        },
      }],
    ];
    if (enableRpx2Vw) {
      defaultPostcssPlugins.push(['@ice/bundles/compiled/postcss-plugin-rpx2vw']);
    }
    const postcssOpts = mergeWith(
      {
        ...defaultPostcssOpts,
        postcssOptions: {
          config: false,
          plugins: defaultPostcssPlugins,
        },
      },
      { postcssOptions: userPostcssOptions },
      (objValue, srcValue) => {
        if (isArray(objValue)) {
          return objValue.concat(srcValue);
        }
      },
    );
    return postcssOpts;
  }
}