Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Jahred Hope committed May 6, 2016
1 parent be75106 commit 730f97a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
24 changes: 22 additions & 2 deletions README.md
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)
11 changes: 11 additions & 0 deletions index.js
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;
12 changes: 12 additions & 0 deletions package.json
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"
}

0 comments on commit 730f97a

Please sign in to comment.