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
Copy file name to clipboardExpand all lines: src/content/configuration/module.mdx
+52-45Lines changed: 52 additions & 45 deletions
Original file line number
Diff line number
Diff line change
@@ -249,13 +249,19 @@ module.exports = {
249
249
}
250
250
```
251
251
252
-
If `Rule.type` is an `asset` then `Rules.parser` option may be an object or function that describes a condition whether to encode file contents to Base64 or emit it as a separate file into the output directory.
252
+
If `Rule.type` is an `asset` then `Rules.parser` option may be an object or a function that describes a condition whether to encode file contents to Base64 or emit it as a separate file into the output directory.
253
253
254
-
If `Rule.type` is an `asset` or `asset/inline` then `Rule.generator` option may be an object that describes an encoding of the module source or a function that encodes a module source by a custom algorithm.
254
+
If `Rule.type` is an `asset` or `asset/inline` then `Rule.generator` option may be an object that describes the encoding of the module source or a function that encodes module's source by a custom algorithm.
255
255
256
-
For more info - see [Asset Modules](/guides/asset-modules/)
256
+
See [Asset Modules guide](/guides/asset-modules/) for additional information and use cases.
If a module source size is less than `maxSize` then module will be injected into the bundle as a Base64-encoded string, otherwise module file will be emitted into the output directory.
263
+
264
+
__webpack.config.js__
259
265
260
266
```js
261
267
module.exports= {
@@ -266,7 +272,7 @@ module.exports = {
266
272
//...
267
273
parser: {
268
274
dataUrlCondition: {
269
-
maxSize:8096
275
+
maxSize:4*1024
270
276
}
271
277
}
272
278
}
@@ -275,19 +281,39 @@ module.exports = {
275
281
}
276
282
```
277
283
278
-
## `dataUrlCondition.minSize`
284
+
When a function is given, returning `true` tells webpack to inject the module into the bundle as Base64-encoded string, otherwise module file will be emitted into the output directory.
279
285
280
-
`number`
286
+
__webpack.config.js__
281
287
282
-
If a module source size is less than `maxSize` then module will be injected into the bundle as a Base64-encoded string, otherwise module file will be emitted into the output directory.
If the function returns true, then module will be injected into the bundle as base64-encoded string, otherwise module file will be emitted into the output directory.
311
+
When `Rule.generator.dataUrl` is used as an object, you can configure two properties:
289
312
290
-
## `Rule.generator.dataUrl` as an object
313
+
- encoding: When set to `'base64'`, module source will be encoded using Base64 algorithm. Setting `encoding` to false will disable encoding.
314
+
- mimetype: A mimetype for data URI. Resolves from module resource extension by default.
315
+
316
+
__webpack.config.js__
291
317
292
318
```js
293
319
module.exports= {
@@ -298,55 +324,36 @@ module.exports = {
298
324
//...
299
325
generator: {
300
326
encoding:'base64',
301
-
mimetype:''
327
+
mimetype:'mimetype/png'
302
328
}
303
329
}
304
330
]
305
331
}
306
332
}
307
333
```
308
334
309
-
## `dataUrl.encoding`
310
-
311
-
`'base' | false`
312
-
313
-
-`base64` - encode a module source with Base64 algorithm
314
-
-`false` - don't encode a module source
315
-
316
-
## `dataUrl.mimetype`
317
-
318
-
`string`
319
-
320
-
A mimetype for data-url. Resolves from module resource extension by default
321
-
322
-
## `Rule.generator.dataUrl` as a function
335
+
When used a a function, it executes for every module and must return a data URI string.
Copy file name to clipboardExpand all lines: src/content/guides/asset-modules.md
+14-18Lines changed: 14 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,12 @@
1
1
---
2
2
title: Asset Modules
3
+
sort: 24
3
4
contributors:
4
5
- smelukov
6
+
- EugeneHlushko
5
7
---
6
8
7
-
Asset Modules is a type of modules that allows to use assets files (fonts, icons, etc) without configuring additional loaders.
9
+
Asset Modules is a type of module that allows to use asset files (fonts, icons, etc) without configuring additional loaders.
8
10
9
11
Prior to webpack 5 it was common to use:
10
12
@@ -19,7 +21,7 @@ Asset Modules type replaces all of these loaders by adding 4 new module types:
19
21
-`asset/source` exports the source code of the asset. Previously achievable by using `raw-loader`.
20
22
-`asset` automatically chooses between exporting a data URI and emitting a separate file. Previously achievable by using `url-loader` with asset size limit.
21
23
22
-
W> This is an experimental feature. Enable Asset Modules by setting `experiments.asset: true` in [experiments](/configuration/experiments/) option of your webpack configuration
24
+
W> This is an experimental feature. Enable Asset Modules by setting `experiments.asset: true` in [experiments](/configuration/experiments/) option of your webpack configuration.
@@ -81,11 +81,11 @@ All `.png` files will be emitted to the output directory and their paths will be
81
81
82
82
By default, `asset/resource` modules are emitting with `[hash][ext]` filename into output directory.
83
83
84
-
You can modify this template by setting `output.assetModuleFilename` in your configuration:
84
+
You can modify this template by setting [`output.assetModuleFilename`](/configuration/output/#outputassetmodulefilename) in your webpack configuration:
Now webpack will automatically choose between `resource` and `inline` by following a default condition: a file with size less than 8kb will be treated as a `inline` module type and `resource` module type otherwise.
280
276
281
-
You can change this condition by setting a `parser.dataUrlCondition.maxSize` option on the module rule of your webpack configuration:
277
+
You can change this condition by setting a [`Rule.parser.dataUrlCondition.maxSize`](/configuration/module/#ruleparserdataurlcondition) option on the module rule level of your webpack configuration:
282
278
283
279
__webpack.config.js__
284
280
@@ -310,4 +306,4 @@ module.exports = {
310
306
};
311
307
```
312
308
313
-
Also you can [specify a function](/configuration/module/#ruleparsedataurlcondition-as-a-function) to decide to inlining a module or not.
309
+
Also you can [specify a function](/configuration/module/#ruleparserdataurlcondition) to decide to inlining a module or not.
0 commit comments