Skip to content

Add support for css modules :export block #14

Description

@xumix

Please, add support for exports, it would be extremely usefull with sass/less other preprocessors

Example .less

@type: "global";
:export {
  red: #db2b21;
  type: @type;
}
.some-style {
display: block;
}

the resulting object would look like this:

{ "some-style": "some-style", "red": "#db2b21", "type": "global" }

Activity

  1. Connormiha commented on Jun 11, 2019

    @Connormiha
    Owner

    @xumix good point! Thanks.
    It supports since 2.5.0.

  2. xumix commented on Jun 12, 2019

    @xumix
    Author

    wow! thnks for fast response!

  3. xumix commented on Jun 12, 2019

    @xumix
    Author

    @Connormiha but I was unable to make my less work, I got all unresolved vars like this:

    { type: '@type' }
    

    my config looks like this:

    module.exports = {
        lessConfig: {
            modules: true,
            namedExport: true,
            camelCase: true
        },
        cssLoaderConfig: {
            exportLocalsStyle: "camelCase"
        }
    };
    

    and jest config:

    "jest": {
        "moduleFileExtensions": [
          "tsx",
          "ts",
          "less",
          "js",
          "json",
          "jsx"
        ],
        "transform": {
          ".+\\.(css|styl|less|sass|scss)$": "jest-css-modules-transform"
        }
      },
    

    looks like you don't have variable expansion tests

  4. xumix commented on Jun 12, 2019

    @xumix
    Author

    I've found the problem: less.render() is actually async so the file contents get returned before render process is completed

  5. xumix commented on Jun 12, 2019

    @xumix
    Author

    The solution looks like this, I suppose

        process(src, path, config) {
            let finishFlag = false;
    ...
            case "less":
                less = less || require("less");
                lessConfig = Object.assign(preProcessorsConfig.lessConfig || {}, { filename: path });
                            less
                    .render(src, lessConfig)
                    .then(output => {
                        textCSS = output.css;
                    })
                    .catch(error => {
                        if (error) {
                            throw error;
                        }
                    })
                    .finally(() => {
                        finishFlag = true;
                    });
                break;
    
            ...
    
            const deasync = require("deasync");
            while (!finishFlag) {
                deasync.runLoopOnce();
            }
    
            return moduleTemplate.replace("%s", JSON.stringify(parser.getCSSSelectors(textCSS, path)));
    
  6. Connormiha commented on Jun 12, 2019

    @Connormiha
    Owner

    Jest tranform works only synchronously. Unfortunately, this hack is the only solution.

  7. Connormiha commented on Jun 12, 2019

    @Connormiha
    Owner

    deasync works unstable. Some times it throws error Assertion failed: (handle->type == UV_TCP || handle->type == UV_TTY || handle->type == UV_NAMED_PIPE), function uv___stream_fd, file ../deps/uv/src/unix/stream.c, line 1617.. So this is unsafe solution.

  8. xumix commented on Jun 12, 2019

    @xumix
    Author

    @Connormiha looks like some bug in nodejs & osx: nodejs/node#8258
    also: abbr/deasync#55 (comment)

  9. xumix commented on Oct 14, 2019

    @xumix
    Author

    @Connormiha any chance you create a repro for the bug? I don't have any osx device available

  10. Connormiha commented on Oct 14, 2019

    @Connormiha
    Owner

    This is a very dangerous change. This lib(deasync) is a hack for node.js flow.
    Let's try a different path. Show here your postcss config. I'll try to come up with something.

  11. xumix commented on Oct 15, 2019

    @xumix
    Author

    @Connormiha it is rather simple:

    module.exports = {
        lessConfig: {
            modules: true,
            namedExport: true,
            camelCase: true
        },
        cssLoaderConfig: {
            exportLocalsStyle: "camelCase"
        }
    };
    
  12. Connormiha commented on Oct 18, 2019

    @Connormiha
    Owner

    @xumix Try version 3.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions