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 }}
This repository was archived by the owner on Mar 17, 2021. It is now read-only.
|**[`limit`](#limit)**|`{Boolean\|Number\|String}`|`true`| Specifying the maximum size of a file in bytes. |
65
+
|**[`mimetype`](#mimetype)**|`{Boolean\|String}`| based from [mime-types](https://github.com/jshttp/mime-types)| Sets the MIME type for the file to be transformed. |
66
+
|**[`encoding`](#encoding)**|`{Boolean\|String}`|`base64`| Specify the encoding which the file will be inlined with. |
67
+
|**[`generator`](#generator)**|`{Function}`|`() => type/subtype;encoding,base64_data`| You can create you own custom implementation for encoding data. |
68
+
|**[`fallback`](#fallback)**|`{String}`|`file-loader`| Specifies an alternative loader to use when a target file's size exceeds the limit. |
69
+
|**[`esModule`](#esmodule)**|`{Boolean}`|`true`| Use ES modules syntax. |
63
70
64
-
Type: `String`
65
-
Default: `'file-loader'`
71
+
### `limit`
66
72
67
-
Specifies an alternative loader to use when a target file's size exceeds the
68
-
limit set in the `limit` option.
73
+
Type: `Boolean|Number|String`
74
+
Default: `undefined`
75
+
76
+
The limit can be specified via loader options and defaults to no limit.
77
+
78
+
#### `Boolean`
79
+
80
+
Enable or disable transform files into base64.
69
81
70
82
**webpack.config.js**
71
83
@@ -79,7 +91,7 @@ module.exports = {
79
91
{
80
92
loader:'url-loader',
81
93
options: {
82
-
fallback:require.resolve('responsive-loader'),
94
+
limit:false,
83
95
},
84
96
},
85
97
],
@@ -89,9 +101,12 @@ module.exports = {
89
101
};
90
102
```
91
103
92
-
The fallback loader will receive the same configuration options as url-loader.
104
+
#### `Number|String`
93
105
94
-
For example, to set the quality option of a responsive-loader above use:
106
+
A `Number` or `String` specifying the maximum size of a file in bytes.
107
+
If the file size is **equal** or **greater** than the limit [`file-loader`](https://github.com/webpack-contrib/file-loader) will be used (by default) and all query parameters are passed to it.
108
+
109
+
Using an alternative to `file-loader` is enabled via the `fallback` option.
95
110
96
111
**webpack.config.js**
97
112
@@ -105,8 +120,7 @@ module.exports = {
105
120
{
106
121
loader:'url-loader',
107
122
options: {
108
-
fallback:require.resolve('responsive-loader'),
109
-
quality:85,
123
+
limit:8192,
110
124
},
111
125
},
112
126
],
@@ -116,19 +130,18 @@ module.exports = {
116
130
};
117
131
```
118
132
119
-
### `limit`
133
+
### `mimetype`
120
134
121
-
Type: `Number|Boolean|String`
122
-
Default: `undefined`
135
+
Type: `Boolean|String`
136
+
Default: based from [mime-types](https://github.com/jshttp/mime-types)
123
137
124
-
The limit can be specified via loader options and defaults to no limit.
138
+
Specify the `mimetype` which the file will be inlined with.
139
+
If unspecified the `mimetype` value will be used from [mime-types](https://github.com/jshttp/mime-types).
125
140
126
-
#### `Number|String`
141
+
#### `Boolean`
127
142
128
-
A `Number` or `String` specifying the maximum size of a file in bytes. If the file size is
129
-
**equal** or **greater** than the limit [`file-loader`](https://github.com/webpack-contrib/file-loader)
130
-
will be used (by default) and all query parameters are passed to it.
131
-
Using an alternative to `file-loader` is enabled via the `fallback` option.
143
+
The `true` value allows to generation the `mimetype` part from [mime-types](https://github.com/jshttp/mime-types).
144
+
The `false` value removes the `mediatype` part from a Data URL (if omitted, defaults to `text/plain;charset=US-ASCII`).
132
145
133
146
**webpack.config.js**
134
147
@@ -142,7 +155,7 @@ module.exports = {
142
155
{
143
156
loader:'url-loader',
144
157
options: {
145
-
limit:8192,
158
+
mimetype:false,
146
159
},
147
160
},
148
161
],
@@ -152,9 +165,9 @@ module.exports = {
152
165
};
153
166
```
154
167
155
-
#### `Boolean`
168
+
#### `String`
156
169
157
-
Enable or disable transform files into base64.
170
+
Sets the MIME type for the file to be transformed.
158
171
159
172
**webpack.config.js**
160
173
@@ -168,7 +181,7 @@ module.exports = {
168
181
{
169
182
loader:'url-loader',
170
183
options: {
171
-
limit:false,
184
+
mimetype:'image/png',
172
185
},
173
186
},
174
187
],
@@ -178,12 +191,17 @@ module.exports = {
178
191
};
179
192
```
180
193
181
-
### `mimetype`
194
+
### `encoding`
182
195
183
-
Type: `String`
184
-
Default: `(file extension)`
196
+
Type: `Boolean|String`
197
+
Default: `base64`
198
+
199
+
Specify the `encoding` which the file will be inlined with.
200
+
If unspecified the `encoding` will be `base64`.
201
+
202
+
#### `Boolean`
185
203
186
-
Sets the MIME type for the file to be transformed. If unspecified the file extensions will be used to lookup the MIME type.
204
+
If you don't want to use any encoding you can set `encoding` to `false` however if you set it to `true` it will use the default encoding `base64`.
187
205
188
206
**webpack.config.js**
189
207
@@ -192,12 +210,12 @@ module.exports = {
192
210
module: {
193
211
rules: [
194
212
{
195
-
test:/\.(png|jpg|gif)$/i,
213
+
test:/\.svg$/i,
196
214
use: [
197
215
{
198
216
loader:'url-loader',
199
217
options: {
200
-
mimetype:'image/png',
218
+
encoding:false,
201
219
},
202
220
},
203
221
],
@@ -207,14 +225,9 @@ module.exports = {
207
225
};
208
226
```
209
227
210
-
### `encoding`
211
-
212
-
Type: `String|Boolean`
213
-
Default: `base64`
214
-
215
-
Specify the encoding which the file will be in-lined with. It supports [Node.js Buffers and Character Encodings](https://nodejs.org/api/buffer.html#buffer_buffers_and_character_encodings) which are `["utf8","utf16le","latin1","base64","hex","ascii","binary","ucs2"]`.
228
+
#### `String`
216
229
217
-
> If you don't want to use any encoding you can set `encoding` to `false` however if you set it to `true` it will use the default encoding `base64`.
230
+
It supports [Node.js Buffers and Character Encodings](https://nodejs.org/api/buffer.html#buffer_buffers_and_character_encodings) which are `["utf8","utf16le","latin1","base64","hex","ascii","binary","ucs2"]`.
You can create you own custom implementation for encoding data.`generator` argument is a [`Buffer`](https://nodejs.org/api/buffer.html) instance of the file. in the example we are compressing svg files using [mini-svg-data-uri](https://github.com/tigt/mini-svg-data-uri) implementation.
259
+
You can create you own custom implementation for encoding data.
By using your own implementation, `mimetype` and `encoding` won't have effect on the final output. until you specify them in the output manually for Example:
293
+
### `fallback`
294
+
295
+
Type: `String`
296
+
Default: `'file-loader'`
297
+
298
+
Specifies an alternative loader to use when a target file's size exceeds the limit set in the `limit` option.
0 commit comments