From 730f97a56d4baa7703a2cd0792181a51ff350784 Mon Sep 17 00:00:00 2001 From: Jahred Hope Date: Fri, 6 May 2016 11:15:20 +1000 Subject: [PATCH] Initial Commit --- README.md | 24 ++++++++++++++++++++++-- index.js | 11 +++++++++++ package.json | 12 ++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 index.js create mode 100644 package.json diff --git a/README.md b/README.md index 6d1b688..5d56302 100644 --- a/README.md +++ b/README.md @@ -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(''; +``` + +[Documentation: Using loaders](http://webpack.github.io/docs/using-loaders.html) + +## License + +MIT (http://www.opensource.org/licenses/mit-license.php) diff --git a/index.js b/index.js new file mode 100644 index 0000000..fc6c7fa --- /dev/null +++ b/index.js @@ -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; diff --git a/package.json b/package.json new file mode 100644 index 0000000..15c10f8 --- /dev/null +++ b/package.json @@ -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 ", + "license": "MIT" +}