@@ -41,11 +41,10 @@ module.exports = {
41
41
module: {
42
42
rules: [
43
43
{
44
- test: / \. (png| jpe? g| gif)$ / ,
44
+ test: / \. (png| jpe? g| gif)$ / i ,
45
45
use: [
46
46
{
47
47
loader: ' file-loader' ,
48
- options: {},
49
48
},
50
49
],
51
50
},
@@ -65,7 +64,7 @@ specified to do so) and returns the public URI of the file.
65
64
### ` name `
66
65
67
66
Type: ` String|Function `
68
- Default: ` '[hash ].[ext]' `
67
+ Default: ` '[contenthash ].[ext]' `
69
68
70
69
Specifies a custom filename template for the target file(s) using the query
71
70
parameter ` name ` . For example, to emit a file from your ` context ` directory into
@@ -80,15 +79,11 @@ module.exports = {
80
79
module: {
81
80
rules: [
82
81
{
83
- test: / \. (png| jpe? g| gif)$ / ,
84
- use: [
85
- {
86
- loader: ' file-loader' ,
87
- options: {
88
- name: ' [path][name].[ext]' ,
89
- },
90
- },
91
- ],
82
+ test: / \. (png| jpe? g| gif)$ / i ,
83
+ loader: ' file-loader' ,
84
+ options: {
85
+ name: ' [path][name].[ext]' ,
86
+ },
92
87
},
93
88
],
94
89
},
@@ -104,21 +99,17 @@ module.exports = {
104
99
module: {
105
100
rules: [
106
101
{
107
- test: / \. (png| jpe? g| gif)$ / ,
108
- use: [
109
- {
110
- loader: ' file-loader' ,
111
- options: {
112
- name (file ) {
113
- if (process .env .NODE_ENV === ' development' ) {
114
- return ' [path][name].[ext]' ;
115
- }
102
+ test: / \. (png| jpe? g| gif)$ / i ,
103
+ loader: ' file-loader' ,
104
+ options: {
105
+ name (file ) {
106
+ if (process .env .NODE_ENV === ' development' ) {
107
+ return ' [path][name].[ext]' ;
108
+ }
116
109
117
- return ' [hash].[ext]' ;
118
- },
119
- },
110
+ return ' [contenthash].[ext]' ;
120
111
},
121
- ] ,
112
+ } ,
122
113
},
123
114
],
124
115
},
@@ -143,15 +134,11 @@ module.exports = {
143
134
module: {
144
135
rules: [
145
136
{
146
- test: / \. (png| jpe? g| gif)$ / ,
147
- use: [
148
- {
149
- loader: ' file-loader' ,
150
- options: {
151
- outputPath: ' images' ,
152
- },
153
- },
154
- ],
137
+ test: / \. (png| jpe? g| gif)$ / i ,
138
+ loader: ' file-loader' ,
139
+ options: {
140
+ outputPath: ' images' ,
141
+ },
155
142
},
156
143
],
157
144
},
@@ -167,31 +154,27 @@ module.exports = {
167
154
module: {
168
155
rules: [
169
156
{
170
- test: / \. (png| jpe? g| gif)$ / ,
171
- use: [
172
- {
173
- loader: ' file-loader' ,
174
- options: {
175
- outputPath : (url , resourcePath , context ) => {
176
- // `resourcePath` is original absolute path to asset
177
- // `context` is directory where stored asset (`rootContext`) or `context` option
157
+ test: / \. (png| jpe? g| gif)$ / i ,
158
+ loader: ' file-loader' ,
159
+ options: {
160
+ outputPath : (url , resourcePath , context ) => {
161
+ // `resourcePath` is original absolute path to asset
162
+ // `context` is directory where stored asset (`rootContext`) or `context` option
178
163
179
- // To get relative path you can use
180
- // const relativePath = path.relative(context, resourcePath);
164
+ // To get relative path you can use
165
+ // const relativePath = path.relative(context, resourcePath);
181
166
182
- if (/ my-custom-image\. png/ .test (resourcePath)) {
183
- return ` other_output_path/${ url} ` ;
184
- }
167
+ if (/ my-custom-image\. png/ .test (resourcePath)) {
168
+ return ` other_output_path/${ url} ` ;
169
+ }
185
170
186
- if (/ images/ .test (context)) {
187
- return ` image_output_path/${ url} ` ;
188
- }
171
+ if (/ images/ .test (context)) {
172
+ return ` image_output_path/${ url} ` ;
173
+ }
189
174
190
- return ` output_path/${ url} ` ;
191
- },
192
- },
175
+ return ` output_path/${ url} ` ;
193
176
},
194
- ] ,
177
+ } ,
195
178
},
196
179
],
197
180
},
@@ -214,15 +197,11 @@ module.exports = {
214
197
module: {
215
198
rules: [
216
199
{
217
- test: / \. (png| jpe? g| gif)$ / ,
218
- use: [
219
- {
220
- loader: ' file-loader' ,
221
- options: {
222
- publicPath: ' assets' ,
223
- },
224
- },
225
- ],
200
+ test: / \. (png| jpe? g| gif)$ / i ,
201
+ loader: ' file-loader' ,
202
+ options: {
203
+ publicPath: ' assets' ,
204
+ },
226
205
},
227
206
],
228
207
},
@@ -238,31 +217,27 @@ module.exports = {
238
217
module: {
239
218
rules: [
240
219
{
241
- test: / \. (png| jpe? g| gif)$ / ,
242
- use: [
243
- {
244
- loader: ' file-loader' ,
245
- options: {
246
- publicPath : (url , resourcePath , context ) => {
247
- // `resourcePath` is original absolute path to asset
248
- // `context` is directory where stored asset (`rootContext`) or `context` option
220
+ test: / \. (png| jpe? g| gif)$ / i ,
221
+ loader: ' file-loader' ,
222
+ options: {
223
+ publicPath : (url , resourcePath , context ) => {
224
+ // `resourcePath` is original absolute path to asset
225
+ // `context` is directory where stored asset (`rootContext`) or `context` option
249
226
250
- // To get relative path you can use
251
- // const relativePath = path.relative(context, resourcePath);
227
+ // To get relative path you can use
228
+ // const relativePath = path.relative(context, resourcePath);
252
229
253
- if (/ my-custom-image\. png/ .test (resourcePath)) {
254
- return ` other_public_path/${ url} ` ;
255
- }
230
+ if (/ my-custom-image\. png/ .test (resourcePath)) {
231
+ return ` other_public_path/${ url} ` ;
232
+ }
256
233
257
- if (/ images/ .test (context)) {
258
- return ` image_output_path/${ url} ` ;
259
- }
234
+ if (/ images/ .test (context)) {
235
+ return ` image_output_path/${ url} ` ;
236
+ }
260
237
261
- return ` public_path/${ url} ` ;
262
- },
263
- },
238
+ return ` public_path/${ url} ` ;
264
239
},
265
- ] ,
240
+ } ,
266
241
},
267
242
],
268
243
},
@@ -283,7 +258,7 @@ module.exports = {
283
258
module: {
284
259
rules: [
285
260
{
286
- test: / \. (png| jpg| gif)$ / ,
261
+ test: / \. (png| jpg| gif)$ / i ,
287
262
loader: ' file-loader' ,
288
263
options: {
289
264
publicPath: ' /some/path/' ,
@@ -307,7 +282,7 @@ module.exports = {
307
282
module: {
308
283
rules: [
309
284
{
310
- test: / \. (png| jpe? g| gif)$ / ,
285
+ test: / \. (png| jpe? g| gif)$ / i ,
311
286
use: [
312
287
{
313
288
loader: ' file-loader' ,
@@ -345,7 +320,7 @@ module.exports = {
345
320
module: {
346
321
rules: [
347
322
{
348
- test: / \. css$ / ,
323
+ test: / \. css$ / i ,
349
324
use: [
350
325
{
351
326
loader: ' file-loader' ,
@@ -382,12 +357,12 @@ module.exports = {
382
357
module: {
383
358
rules: [
384
359
{
385
- test: / \. (png| jpe? g| gif)$ / ,
360
+ test: / \. (png| jpe? g| gif)$ / i ,
386
361
use: [
387
362
{
388
363
loader: ' file-loader' ,
389
364
options: {
390
- regExp: / \/ ([a-z0-9 ] + )\/ [a-z0-9 ] + \. png$ / ,
365
+ regExp: / \/ ([a-z0-9 ] + )\/ [a-z0-9 ] + \. png$ / i ,
391
366
name: ' [1]-[name].[ext]' ,
392
367
},
393
368
},
@@ -453,6 +428,13 @@ Default: `md5`
453
428
454
429
Specifies the hash method to use for hashing the file content.
455
430
431
+ ### ` [contenthash] `
432
+
433
+ Type: ` String `
434
+ Default: ` md5 `
435
+
436
+ Specifies the hash method to use for hashing the file content.
437
+
456
438
### ` [<hashType>:hash:<digestType>:<length>] `
457
439
458
440
Type: ` String `
@@ -492,6 +474,8 @@ The n-th match obtained from matching the current file name against the `regExp`
492
474
493
475
## Examples
494
476
477
+ ### Names
478
+
495
479
The following examples show how one might use ` file-loader ` and what the result would be.
496
480
497
481
** file.js**
@@ -507,12 +491,12 @@ module.exports = {
507
491
module: {
508
492
rules: [
509
493
{
510
- test: / \. (png| jpe? g| gif)$ / ,
494
+ test: / \. (png| jpe? g| gif)$ / i ,
511
495
use: [
512
496
{
513
497
loader: ' file-loader' ,
514
498
options: {
515
- name: ' dirname/[hash ].[ext]' ,
499
+ name: ' dirname/[contenthash ].[ext]' ,
516
500
},
517
501
},
518
502
],
@@ -544,7 +528,7 @@ module.exports = {
544
528
module: {
545
529
rules: [
546
530
{
547
- test: / \. (png| jpe? g| gif)$ / ,
531
+ test: / \. (png| jpe? g| gif)$ / i ,
548
532
use: [
549
533
{
550
534
loader: ' file-loader' ,
@@ -581,12 +565,12 @@ module.exports = {
581
565
module: {
582
566
rules: [
583
567
{
584
- test: / \. (png| jpe? g| gif)$ / ,
568
+ test: / \. (png| jpe? g| gif)$ / i ,
585
569
use: [
586
570
{
587
571
loader: ' file-loader' ,
588
572
options: {
589
- name: ' [path][name].[ext]?[hash ]' ,
573
+ name: ' [path][name].[ext]?[contenthash ]' ,
590
574
},
591
575
},
592
576
],
@@ -641,15 +625,13 @@ module.exports = {
641
625
module: {
642
626
rules: [
643
627
{
644
- test: / \. (png| jpg| gif)$ / ,
628
+ test: / \. (png| jpg| gif)$ / i ,
645
629
loader: ' file-loader' ,
646
630
options: {
647
- context: ' ' ,
648
- emitFile: true ,
649
- name: ' [name].[hash].[ext]' ,
631
+ name: ' [name].[contenthash].[ext]' ,
632
+ outputPath: ' static/assets/' ,
650
633
publicPath: ' static/assets/' ,
651
634
postTransformPublicPath : (p ) => ` __webpack_public_path__ + ${ p} ` ,
652
- outputPath: ' static/assets/' ,
653
635
},
654
636
},
655
637
],
0 commit comments