This repository was archived by the owner on Mar 17, 2021. It is now read-only.
File tree 3 files changed +42
-1
lines changed
3 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,15 @@ var url = require("file!./file.png");
13
13
By default the filename of the resulting file is the MD5 hash of the file's contents
14
14
with the original extension of the required resource.
15
15
16
+ By default a file is emitted, however this can be disabled if required (e.g. for server
17
+ side packages).
18
+
19
+ ``` javascript
20
+ var url = require (" file?emitFile=false!./file.png" );
21
+ // => returns the public url but does NOT emit a file
22
+ // => returns i. e. "/public-path/0dcbbaa701328a3c262cfd45869e351f.png"
23
+ ```
24
+
16
25
## Filename templates
17
26
18
27
You can configure a custom filename template for your file using the query
Original file line number Diff line number Diff line change @@ -13,7 +13,10 @@ module.exports = function(content) {
13
13
content : content ,
14
14
regExp : query . regExp
15
15
} ) ;
16
- this . emitFile ( url , content ) ;
16
+
17
+ if ( query . emitFile === undefined || query . emitFile ) {
18
+ this . emitFile ( url , content ) ;
19
+ }
17
20
return "module.exports = __webpack_public_path__ + " + JSON . stringify ( url ) + ";" ;
18
21
}
19
22
module . exports . raw = true ;
Original file line number Diff line number Diff line change
1
+ var should = require ( "should" ) ;
2
+ var fileLoader = require ( "../" ) ;
3
+
4
+ function run ( resourcePath , query , content ) {
5
+ content = content || new Buffer ( "1234" ) ;
6
+ var result = false ;
7
+ var context = {
8
+ resourcePath : resourcePath ,
9
+ query : "?" + query ,
10
+ options : {
11
+ context : "/this/is/the/context"
12
+ } ,
13
+ emitFile : function ( url , content2 ) {
14
+ result = true ;
15
+ }
16
+ } ;
17
+ fileLoader . call ( context , content ) ;
18
+ return result ;
19
+ }
20
+
21
+ describe ( "optional-emission" , function ( ) {
22
+ it ( "should emit a file by default" , function ( ) {
23
+ run ( "whatever.txt" , "" ) . should . be . true ;
24
+ } ) ;
25
+
26
+ it ( "should not emit a file if disabled" , function ( ) {
27
+ run ( "whatever.txt" , "emitFile=false" ) . should . be . false ;
28
+ } ) ;
29
+ } ) ;
You can’t perform that action at this time.
0 commit comments