Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass resourceQuery to modules.auto callback #1566

Closed
erropix opened this issue Jan 22, 2024 · 2 comments · Fixed by #1569
Closed

Pass resourceQuery to modules.auto callback #1566

erropix opened this issue Jan 22, 2024 · 2 comments · Fixed by #1569

Comments

@erropix
Copy link

erropix commented Jan 22, 2024

Modification Proposal

Pass the resourceQuery as a second argument to the modules.auto function callback.

type auto = boolean | regExp | ((resourcePath: string, resourceQuery: string) => boolean);

Expected Behavior / Situation

You should be able to return true or false based on the resource query. Specially with the vue-loader style module

Actual Behavior / Situation

You only have access to the resource path which doesn't include any information about if the module attribute is set in the style block or not.

The current workaround is to use conditional rules like shown here https://vue-loader.vuejs.org/guide/css-modules.html#opt-in-usage

But this solution is not optimal when there are multiple loaders applied to both CSS and Sass assets.

Please paste the results of npx webpack-cli info here, and mention other relevant information

System:
  OS: Windows 10 10.0.19045
  CPU: (12) x64 Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
  Memory: 17.48 GB / 31.91 GB
Binaries:
  Node: 20.10.0 - ~\scoop\apps\nodejs-lts\current\node.EXE
  Yarn: 1.22.19 - ~\scoop\apps\yarn\current\bin\yarn.CMD
  npm: 10.2.5 - ~\scoop\apps\nodejs-lts\current\bin\npm.CMD
Browsers:
  Edge: Chromium (120.0.2210.144)
  Internet Explorer: 11.0.19041.3636
Packages:
  copy-webpack-plugin: ^12.0.2 => 12.0.2
  css-loader: ^6.9.1 => 6.9.1
  postcss-loader: ^8.0.0 => 8.0.0
  sass-loader: ^14.0.0 => 14.0.0
  style-loader: ^3.3.4 => 3.3.4
  svgo-loader: ^4.0.0 => 4.0.0
  swc-minify-webpack-plugin: ^2.1.1 => 2.1.1
  vue-loader: ^17.4.2 => 17.4.2
  webpack: ^5.89.0 => 5.89.0
  webpack-bundle-analyzer: ^4.10.1 => 4.10.1
  webpack-cli: ^5.1.4 => 5.1.4
  webpack-dev-server: ^4.15.1 => 4.15.1
  webpack-manifest-plugin: ^5.0.0 => 5.0.0
@erropix
Copy link
Author

erropix commented Jan 22, 2024

Based on my quick research, this should be easy to add in here:

css-loader/src/utils.js

Lines 647 to 648 in f9192ee

} else if (typeof modulesOptions.auto === "function") {
const isModule = modulesOptions.auto(resourcePath);

@alexander-akait
Copy link
Member

Feel free to send a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants