file-loader
Advanced tools
Comparing version 0.1.2 to 0.5.0
40
index.js
@@ -5,16 +5,30 @@ /* | ||
*/ | ||
module.exports = function(postfix, prefix) { | ||
postfix = postfix || ""; | ||
prefix = prefix || ""; | ||
return function(content) { | ||
this.cacheable && this.cacheable(); | ||
if(!this.emitFile) throw new Error("emitFile is required from module system"); | ||
if(this.buffers) content = this.buffers[0]; | ||
hash = new (require("crypto").Hash)("md5"); | ||
var loaderUtils = require("loader-utils"); | ||
module.exports = function(content) { | ||
this.cacheable && this.cacheable(); | ||
if(!this.emitFile) throw new Error("emitFile is required from module system"); | ||
var query = loaderUtils.parseQuery(this.query); | ||
var url; | ||
if(query.name) { | ||
url = query.name; | ||
} else { | ||
var prefix = query.prefix || ""; | ||
var postfix = query.postfix; | ||
if(typeof postfix != "string") { | ||
if(this.resource && typeof postfix != "boolean") { | ||
var idx = this.resource.lastIndexOf("."); | ||
if(idx > 0) postfix = this.resource.substr(idx); | ||
else postfix = ""; | ||
} else postfix = ""; | ||
} | ||
var digest = query.hash || "md5"; | ||
var digestSize = query.size || 9999; | ||
hash = new (require("crypto").Hash)(digest); | ||
hash.update(content); | ||
var hash = hash.digest("hex"); | ||
var url = prefix + hash + postfix; | ||
this.emitFile(url, content); | ||
return "module.exports = " + require("webpack/api/getPublicPrefix") + " + " + JSON.stringify(url); | ||
var hash = hash.digest("hex").substr(0, digestSize); | ||
url = prefix + hash + postfix; | ||
} | ||
} | ||
this.emitFile(url, content); | ||
return "module.exports = __webpack_public_path__ + " + JSON.stringify(url); | ||
} | ||
module.exports.raw = true; |
{ | ||
"name": "file-loader", | ||
"version": "0.1.2", | ||
"version": "0.5.0", | ||
"author": "Tobias Koppers @sokra", | ||
"description": "file loader module for webpack", | ||
"dependencies": { | ||
"loader-utils": "0.2.x" | ||
}, | ||
"licenses": [ | ||
@@ -11,4 +14,3 @@ { | ||
} | ||
], | ||
"license": "MIT" | ||
] | ||
} |
@@ -10,18 +10,26 @@ # file loader for webpack | ||
If you want to have a custom extension on your file, I have some prepared: | ||
The filename is the md5 hash of the file. The extension of the required resource is appended. | ||
If you want to have custom pre- and postfix of your file: | ||
``` javascript | ||
require("file/js!./javascript.js"); | ||
require("file/html!./page.html"); | ||
require("file/txt!./flash.txt"); | ||
require("file/png!./image.png"); | ||
require("file/jpg!./image.jpg"); | ||
require("file/jpeg!./image.jpeg"); | ||
require("file/swf!./flash.swf"); | ||
require("file?prefix=js/&postfix=.script.js!./javascript.js"); | ||
// => js/0dcbbaa701328a3c262cfd45869e351f.script.js | ||
require("file?prefix=html-&size=6!./page.html"); | ||
// => html-109fa8.html | ||
require("file?postfix!./flash.txt"); | ||
// => c31e9820c001c9c4a86bce33ce43b679 | ||
require("file?hash=sha512!./image.png"); | ||
// => a720b9f140d13...781f1f78344.png | ||
// use sha512 hash instead of md5 | ||
require("file?name=picture.png!./myself.png"); | ||
// => picture.png | ||
``` | ||
Look at the source to write your own. Pre- and postfix is possible. | ||
## License | ||
MIT (http://www.opensource.org/licenses/mit-license.php) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34
2312
1
3
32
+ Addedloader-utils@0.2.x
+ Addedbig.js@3.2.0(transitive)
+ Addedemojis-list@2.1.0(transitive)
+ Addedjson5@0.5.1(transitive)
+ Addedloader-utils@0.2.17(transitive)
+ Addedobject-assign@4.1.1(transitive)