Subscribe on changes!

[Feature Request]Support access css module in top level of SFC

avatar
May 16th 2022

What problem does this feature solve?

For Vue3, useCssModule can only be called in setup. For Vue2, $style can only be accessed by instance.

Sometimes i want to use css module in SFC but outside instance scope, such as:

// component.vue
<script>
export function someExportedFn() {
  // how can i get css module here?
}
</script>

I don't think technically this should be prevented, css module should be accessible from anywhere in SFC.

What does the proposed API look like?

I haven't found a perfect solution yet. It seems use loader to resolve the problem is a feasible way.

avatar
May 17th 2022

If this CSS module needs to be accessible to external code, why place it in the component? You can just move it to an external *.module.css file which can then be imported anywhere.

I think this use case is to niche to warrant a dedicated API, and there is an obvious workaround.