Skip to content

Commit 85225d4

Browse files
spence-schenxsan
andauthored
docs(guides): Update asset-modules.md (#4544)
* Update asset-modules.md webpack-contrib/raw-loader#107 * Apply suggestions from code review * Update src/content/guides/asset-modules.md Co-authored-by: Sam Chen <[email protected]>
1 parent 90f49c5 commit 85225d4

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

src/content/guides/asset-modules.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ contributors:
66
- EugeneHlushko
77
- chenxsan
88
- anshumanv
9+
- spence-s
910
related:
1011
- title: webpack 5 - Asset Modules
1112
url: https://dev.to/smelukov/webpack-5-asset-modules-2o3h
@@ -388,3 +389,48 @@ module.exports = {
388389
```
389390
390391
Also you can [specify a function](/configuration/module/#ruleparserdataurlcondition) to decide to inlining a module or not.
392+
393+
## Replacing Inline Loader Syntax
394+
395+
Before Asset Modules and Webpack 5, it was possible to use [inline syntax](https://webpack.js.org/concepts/loaders/#inline) with the legacy loaders mentioned above.
396+
397+
It is now reccomended to remove all inline loader syntax and use a resourceQuery condition to mimic the functionality of the inline syntax.
398+
399+
For example, in the case of replacing `raw-loader` with `asset/source` type:
400+
401+
```diff
402+
- import myModule from 'raw-loader!my-module';
403+
+ import myModule from 'my-module?raw';
404+
```
405+
406+
and in the webpack configuration:
407+
408+
```diff
409+
module: {
410+
rules: [
411+
// ...
412+
+ {
413+
+ resouceQuery: /raw/
414+
+ type: 'asset/source'
415+
+ }
416+
]
417+
},
418+
```
419+
420+
and if you'd like to exclude raw assets from being parsed by other loaders, use a negative lookahead:
421+
422+
```diff
423+
module: {
424+
rules: [
425+
// ...
426+
+ {
427+
+ test: /\.m?js$/,
428+
+ resourceQuery: /^(?!raw$).*/,
429+
+ },
430+
{
431+
resouceQuery: /raw/
432+
type: 'asset/source'
433+
}
434+
]
435+
},
436+
```

0 commit comments

Comments
 (0)