Open yuki153 opened 10 months ago
@yuki153 Thanks for reporting the issue!
happy-css-modules resolves ~foo
to node_modules/foo
by default. Perhaps the resolve mechanism is taking precedence over resolve.alias
.
I think the problem will be solved if resolve.alias
takes precedence over ~
resolve. However, I am not sure if it is compatible with css-loader, scss-loader, and less-loader.
happy-css-modules mimics the resolve mechanism of existing tools to avoid compatibility issues. So I think we need to investigate the precedence order of the resolve mechanism in css-loader, scss-loader, and less-loader.
As a workaround, you can use @
instead of ~
for alias.
Also, you should use --webpackResolveAlias='{\"@\": \". /... /src\"}'
instead of --webpackResolveAlias='{\"@\": \"src\"}'
. The alias should be relative to the directory where happy-css-modules
is executed.
// test2.module.scss
@use "@/styles/shared.module.scss" as shared;
.headline {
font-size: 24px;
color: shared.$accentColor3;
}
{
// ...
"scripts": {
// ...
"hcm": "hcm 'src/**/*.module.scss' --webpackResolveAlias='{\"@\": \"src\"}'"
},
// ...
}
Hello, thank you for the great tool. I had a question about this tool and created this issue.
Link to the code that reproduces this issue
https://github.com/yuki153/test-hcm-with-nextjs
To Reproduce
※ The code for reproduction uses next.js v14.0.4(latest) but, other version (e.g. v12.0.4) also reproduces.
Problem description
Path resolution of next.js succeed, but happy-css-module only fail to resolve path.
Below code that uses alias path at
@use
fail to path resolve, so d.ts file also doesn't make. But commented out code that does not use alias succeed to make d.ts file.Value of webpackResolveAlias is
{"~": "../../src"}
. Am I mistaken about how to use this alias option?Error log