Repository navigation
Add support for css modules :export block #14
Description
Activity
@xumix good point! Thanks.
It supports since2.5.0.wow! thnks for fast response!
@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
I've found the problem:
less.render()is actually async so the file contents get returned before render process is completedThe 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)));Jest tranform works only synchronously. Unfortunately, this hack is the only solution.
deasyncworks unstable. Some times it throws errorAssertion 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.@Connormiha looks like some bug in nodejs & osx: nodejs/node#8258
also: abbr/deasync#55 (comment)@Connormiha any chance you create a repro for the bug? I don't have any osx device available
This is a very dangerous change. This lib(deasync) is a hack for node.js flow.
Let's try a different path. Show here yourpostcssconfig. I'll try to come up with something.@Connormiha it is rather simple:
module.exports = { lessConfig: { modules: true, namedExport: true, camelCase: true }, cssLoaderConfig: { exportLocalsStyle: "camelCase" } };@xumix Try version
3.1.0
Please, add support for exports, it would be extremely usefull with sass/less other preprocessors
Example
.lessthe resulting object would look like this: