Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getJSON generates wrong local class name when working with precss(postcssPresetEnv). #104

Open
jngbng opened this issue Apr 17, 2020 · 0 comments

Comments

@jngbng
Copy link

jngbng commented Apr 17, 2020

problem

when working along with postcss-logical module,
postcss-modules generate wrong class name mapping JSON.

postcss-logical is part of postcss-preset-env with stage >= 2 and postcss-preset-env is part of precss.

version:

  • "gulp-postcss": "8.0.0",
  • "postcss-modules": "1.5.0",
  • "precss": "4.0.0",
    • "postcss-preset-env": "6.7.0"

input:

gulpfile.js

gulp
  .src('css/broken.css')
  .pipe(postcss([
    postcssPresetEnv(),  // <--- part of precss that causes problem.
    postcssModules({
        getJSON: async function genJson(absoluteCssPath, json) {
          console.log(JSON.stringify(json, null, 2));
        },
     }),
  ]))
  .pipe(gulp.dest('build'))

css/broken.css

.block {
    color: gray;
}

output:

build/broken.css

._block_1higo_1 {
    color: gray;
}

stdout
expected

{
  "block": "_block_1higo_1"
}

but, actually got

{
  "block-top": "_block_1higo_1",
  "block-bottom": "_block_1higo_1"
}

workaround

Fast workarounds are:

a) to set stage 3 for postcss-preset-env

  .pipe(postcss([
    postcssPresetEnv({stage: 3}),  // <--- part of precss that causes problem.
    postcssModules(),
  ]))

b) disable 'postcssLogical' featrue

  .pipe(postcss([
    postcssPresetEnv({
      features: {
        'logical-properties-and-values': false,   // <--- causes problem.
      }
    }),
    postcssModules(),
  ]))

b) do not merge two plugins

  .pipe(postcss([postcssPresetEnv()])
  .pipe(postcssModules())
@jngbng jngbng changed the title getJSON generate wrong local class name when working with precss(postcssPresetEnv). getJSON generates wrong local class name when working with precss(postcssPresetEnv). Apr 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant