postcss-modules
postcss-modules copied to clipboard
Expose importer in resolve method
The resolve method should be given the filename that triggered the resolve, this is necessary especially for nested imports where the file could be located somewhere else.
postcssModules({
resolve (id, from) {
return path.resolve(from, id);
},
});
The resolver method should also be passed when resolving nested dependencies, currently the following case is impossible to do:
Let's say that the project root is also aliased to ~
/* styles/controls.css */
.control {
border-radius: 4px;
/* ... */
}
/* components/Button/Button.module.css */
.button {
composes: control from '~/styles/controls.css';
/* ... */
}
/* components/Menu/MenuItem.module.css */
.button {
composes: button from '~/components/Button/Button.module.css';
/* ... */
}
MenuItem.module.css
succeeds in resolving Button.module.css
, but because the resolve method isn't passed when parsing the source, it fails when trying to resolve its dependencies.
@madyankin @intrnl created a PR for this: #142 which implements this behavior in a non-breaking way.