-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jahred Hope
committed
May 6, 2016
1 parent
be75106
commit 730f97a
Showing
3 changed files
with
45 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,22 @@ | ||
# base64-image-loader | ||
base64 image loader for webpack | ||
# base64 image loader for webpack | ||
|
||
Easily switched out for a url loader this loader can be injected directly into an img src tag | ||
|
||
If your looking for a loader that simple encodes as base64 try [base64-loader](https://github.com/antelle/base64-loader) | ||
|
||
## Installation | ||
|
||
`npm install base64-image-loader` | ||
|
||
## Usage | ||
|
||
``` javascript | ||
var fileAsBase64Src = require("base64-image!./file.png"); | ||
document.write('<img src="' + fileAsBase64Src + '" />'; | ||
``` | ||
[Documentation: Using loaders](http://webpack.github.io/docs/using-loaders.html) | ||
## License | ||
MIT (http://www.opensource.org/licenses/mit-license.php) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
|
||
function getFileExtension(path) { | ||
return path.split('.').pop(); | ||
} | ||
|
||
module.exports = function(content) { | ||
this.cacheable && this.cacheable(); | ||
return `module.exports = "data:image/${getFileExtension(this.resourcePath)};base64,${content.toString('base64')}"`; | ||
}; | ||
module.exports.raw = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "base64-image-loader", | ||
"version": "0.0.1", | ||
"description": "base64 image loader for webpack", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/jahredhope/base64-image-loader.git" | ||
}, | ||
"main": "index.js", | ||
"author": "Jahred Hope <[email protected]>", | ||
"license": "MIT" | ||
} |