postcss / postcss-custom-properties

Use Custom Properties in CSS
https://postcss.github.io/postcss-custom-properties
MIT License
596 stars 77 forks source link

preserve: false dosen't work with @import #204

Open chybisov opened 4 years ago

chybisov commented 4 years ago

Hi, preserve: false dosen't work with css @import, however preserve: true works great. If index.css looks like

:root {
  --some-color: red;
}

body {
  color: var(--some-color);
}

then output will be correct

body {
  color: red;
}

If we have colors.css and index.css and import colors.css to index like this

@import 'colors.css';

body {
  color: var(--some-color);
}

then output will be

body {
  color: var(--some-color);
}

I'm using postcss-custom-properties with postcss-preset-env and webpack.

webpack.config.js

...
const loaders = [
      isEnvDevelopment && require.resolve('style-loader'),
      isEnvProduction && {
        loader: MiniCssExtractPlugin.loader,
        options: shouldUseRelativeAssetPaths ? { publicPath: '../../' } : {},
      },
      {
        loader: require.resolve('css-loader'),
        options: cssOptions,
      },
      {
        loader: require.resolve('postcss-loader'),
        options: {
          ident: 'postcss',
          plugins: () => [
            require('postcss-flexbugs-fixes'),
            require('postcss-preset-env')({
              autoprefixer: {
                flexbox: 'no-2009',
              },
              preserve: false,
              stage: 3,
            }),
            postcssNormalize(),
          ],
          sourceMap: isEnvProduction && shouldUseSourceMap,
        },
      },
    ];
...