postcss-plugins icon indicating copy to clipboard operation
postcss-plugins copied to clipboard

exportTo doesn't transform/transpile values before exporting

Open minimit opened this issue 5 years ago • 2 comments

Hello, this seems a problem to me. With exportTo you tipically want already transformed values, this works if you have postcss plugins before postcss-preset-env, but postcss-preset-env should export after all transformations or you end up with unusable code when importing from javascript.

For example this is the result of exportTo of postcss-preset-env:

module.exports = {
	customProperties: {
		'--white': '#fff',
		'--black': '#000',
		'--gray--200': '#eff4fd',
		'--gray--300': '#d6e1f6',
		'--gray--500': '#7a7e8e',
		'--gray--900': '#373944',
		'--primary': '#7567f8',
		'--primary--dark': 'color-mod(var(--primary) blackness(5%))',
		'--secondary': 'var(--gray--200)',
		'--secondary--dark': 'color-mod(var(--secondary) blackness(5%))',
		'--text': 'var(--gray--900)',
		'--text--dark': 'var(--black)',
		'--text--inverse': 'var(--white)',
		'--text--inverse--dark': 'var(--gray--200)',

You can see that color-mod isn't transpiled, not even the css custom properties that use other custom properties.

This is my config:

const path = require('path')
const fs = require('fs')

module.exports = {
  parser: 'postcss-scss',
  map: true,
  plugins: {
    'postcss-import': {},
    'postcss-mixins': {},
    'postcss-nesting': {},
    'postcss-simple-vars': {},
    'postcss-extend-rule': {},
    'postcss-object-fit-images': {},
    'postcss-preset-env': {
      stage: 0,
      exportTo: 'dist/test.js',
      features: {
        'color-mod-function': { unresolved: 'warn' }
      }
    },
    autoprefixer: {}
  }
}

Thank you

minimit avatar Oct 07 '19 18:10 minimit

Caused by incorrect execution order between different plugins.

To resolve :

  • [ ] update all plugins so they do not use Once.
  • [ ] collect exports only in OnceExit.

We do need to pinpoint first if the current behaviour is not a feature to some users.

romainmenke avatar Jan 02 '22 15:01 romainmenke

see : https://github.com/csstools/postcss-plugins/issues/151

These features will be removed in the future. We will likely find or create a replacement that is not included in postcss-preset-env

We will not implement extra features for now.

romainmenke avatar Jan 22 '22 12:01 romainmenke

The replacement for this feature is postcss-extract

This plugin allows you to specify if you want to extract values early (before transforms) or late (after transforms).

If you have any issues using that plugin, please let us know in a new issue.

romainmenke avatar Nov 07 '22 21:11 romainmenke