You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Context dependencies should support resource queries #5730
There is no way to pass a resource query when using context dependencies via require.context. In other words, this.resourceQuery will never be set inside a loader when using require.context.
If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
this.resourceQuery should be set in a loader for something like the following:
I have a test case and a proposed fix in my fork here - anuraaga#1
If the approach seems reasonable, I would be happy to move the PR to this repo for tweaks/submission, otherwise someone more familiar with the webpack design should probably take over as I just stumbled to that solution :)
If this is a feature request, what is motivation or use case for changing the behavior?
Some loaders (e.g. sharp-loader) use this.resourceQuery to enable certain behavior. This functionality cannot be used with context dependencies due to having no way to set a resource query. There doesn't seem to be any reason context dependencies should not support this feature as the only difference compared to a normal dependency is multiple files are resolved at the same time and placed in a map.
Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.
So just to clarify, the original request is specifically about require.context not import or import() The latter two have worked with resource queries for a while, but the require function returned by require.context has no facility for passing the resource query along.
So, for example, let's say we want to write a rule to use a different svg loader based on the resource query...something like this:
Original problem was resolved, if you still have a problem, please create a new issue, other issue #12900, test is preferred over resourceQuery, so if you have intersection for test, you need specify resourceQuery for both rules, i.e. resourceQuery: /raw/, and resourceQuery: /^(?!\?raw$).*/,
Activity
sokra commentedon Sep 28, 2017
Yep, send a PR
ogonkov commentedon May 29, 2018
Provided PR doesn't seems working for imports like this
../foo/${bar}.foo?my-queryShould i make PR to support queries like the one above?
ogonkov commentedon May 29, 2018
resourceQuerymake it way toregExphere, is it expected behaviour, @sokra ?webpack/lib/dependencies/ContextDependencyHelpers.js
Line 100 in d2aca56
webpack-bot commentedon Nov 28, 2018
This issue had no activity for at least half a year.
It's subject to automatic issue closing if there is no activity in the next 15 days.
ogonkov commentedon Nov 28, 2018
I believe it still an issue
webpack-bot commentedon May 29, 2019
This issue had no activity for at least half a year.
It's subject to automatic issue closing if there is no activity in the next 15 days.
alexander-akait commentedon May 29, 2019
@ogonkov Problem still exists?
14 remaining items
jclow-sift commentedon Nov 12, 2020
So just to clarify, the original request is specifically about
require.contextnotimportorimport()The latter two have worked with resource queries for a while, but the require function returned byrequire.contexthas no facility for passing the resource query along.So, for example, let's say we want to write a rule to use a different svg loader based on the resource query...something like this:
With that rule, this import of foo.svg ends up using that set of loaders:
import './foo.svg?sprite';but something like this does not:
jclow-sift commentedon Nov 13, 2020
For anybody landing here after struggling with this and
require.context, take a look at https://webpack.js.org/concepts/loaders/#inline for possible solutionsalexander-akait commentedon Mar 15, 2021
Original problem was resolved, if you still have a problem, please create a new issue, other issue #12900,
testis preferred overresourceQuery, so if you have intersection fortest, you need specifyresourceQueryfor both rules, i.e.resourceQuery: /raw/,andresourceQuery: /^(?!\?raw$).*/,