Giter Site home page Giter Site logo

Comments (11)

princed avatar princed commented on June 16, 2024

@kumarharsh Let's move here.

Could you please show how do use @value in your css?

from postcss-modules-values-replace.

kumarharsh avatar kumarharsh commented on June 16, 2024

I'm using @value like this:

/* src/css/shared/colors.css */
@value mainBg: #456371;
/* src/modules/page/page.css */
@value mainBg from "css/shared/colors";  /* using webpack's resolve.moduleDirectory */

.page {
  background-color: mainBg;
  color: color(mainBg lightness(+30%));
}

from postcss-modules-values-replace.

princed avatar princed commented on June 16, 2024
  1. Do you check it in webpack-dev-server?

@value mainBg from "css/shared/colors"; /* using webpack's resolve.moduleDirectory */

It knows nothing about resolve.moduleDirectory at the moment.

from postcss-modules-values-replace.

kumarharsh avatar kumarharsh commented on June 16, 2024

It miraculously started working just now. I cannot explain it myself, but it's somehow reading the resolve.moduleDirectory correctly!

Also, I'm working with webpack's dev server (watch mode).

from postcss-modules-values-replace.

princed avatar princed commented on June 16, 2024

Well, it probably could work this way if you provide webpack's filesystem to plugin.

from postcss-modules-values-replace.

princed avatar princed commented on June 16, 2024

Should you have any questions, feel free to reopen issue.

from postcss-modules-values-replace.

kumarharsh avatar kumarharsh commented on June 16, 2024

@princed I got it working: https://github.com/kumarharsh/postcss-value-replace-test

I was mistaken beforehand when I had claimed that it was reading webpack's resolve.moduleDirectory properly, atleast in my reduced use-case. It doesn't - you were right. Also, passing require('postcss-modules-values-replace')({fs: webpack._compiler.inputFileSystem}) doesn't do much.

My theory as to why this was happening is:

  1. postcss-modules-values-replace was not running, because the config was somehow wrong. Apparently if I write this config:
module.exports = {
  plugins: (webpack) => {
    return [
      require('postcss-modules-values-replace')({fs: webpack._compiler.inputFileSystem}),
      require('postcss-color-function'),
    ];
  },
}

in the postcss.config.js file, it doesn't run. It can't find webpack. but when I shifted it to webpack.config.js it did run:

{
  ...
  postcss: (webpack) => {
    return [
      require('postcss-modules-values-replace')({fs: webpack._compiler.inputFileSystem}),
      require('postcss-color-function'),
    ];
  },
}
  1. So, instead of postcss-modules-values-replace, the postcss-modules-values was running which was included by default in css-loader. This plugin was the one replacing the @value values in my code. And the color() function was definitely not working - I was wrong in judging that it was miraculously working 😄.

I'd like to see #1 land, so that working with this in webpack's system becomes more productive. Thank you for your time.

from postcss-modules-values-replace.

kumarharsh avatar kumarharsh commented on June 16, 2024

Also, this plugin is in ES6, and doing a require('...') throws an error. It'd be nice if there was a pre-compiled version too.

from postcss-modules-values-replace.

princed avatar princed commented on June 16, 2024

Great!

  1. In postcss.config.js you have to use yet another form:
module.exports = (ctx) => ({
   plugins: [
     require('postcss-modules-values-replace')({fs: ctx.webpack._compiler.inputFileSystem}),
     require('postcss-color-function'),
  ]
});

BTW, to make color() work inside @value we need it support media queries, as I mention in README. So it would be nice to have it there in case you're interested.

from postcss-modules-values-replace.

kumarharsh avatar kumarharsh commented on June 16, 2024

@princed Oh, thanks for that. As for the second part of your comment,
do you mean this?

@value mainBg: color(red lightness(+10%));

As of this moment, I don't need to use color() inside @value like this. But if it comes, it'll be great.

from postcss-modules-values-replace.

princed avatar princed commented on June 16, 2024

@value mainBg: color(red lightness(+10%));

Yes, exactly this.

from postcss-modules-values-replace.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.