Skip to content

Commit

Permalink
Add a loader demo
Browse files Browse the repository at this point in the history
  • Loading branch information
bebraw committed Mar 7, 2017
1 parent 0cab6f8 commit 38737f9
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions demo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foobar
16 changes: 16 additions & 0 deletions loaders/demo-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const loaderUtils = require('loader-utils');

module.exports = function(input) {
const { text } = loaderUtils.getOptions(this);

return input + text;
};
module.exports.pitch = function(remainingRequest, precedingRequest, input) {
console.log(
'remaining request', remainingRequest,
'preceding request', precedingRequest,
'input', input
);

return 'pitched';
};
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
"karma-mocha": "^1.3.0",
"karma-phantomjs-launcher": "^1.0.2",
"karma-webpack": "^2.0.2",
"loader-runner": "^2.3.0",
"loader-utils": "^1.0.3",
"mocha": "^3.2.0",
"mocha-loader": "^1.1.1",
"optimize-css-assets-webpack-plugin": "^1.3.0",
Expand Down
23 changes: 23 additions & 0 deletions run-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const fs = require('fs');
const path = require('path');
const { runLoaders } = require('loader-runner');

runLoaders({
resource: './demo.txt',
loaders: [
{
loader: path.resolve(__dirname, './loaders/demo-loader'),
options: {
text: 'demo',
},
},
],
readResource: fs.readFile.bind(fs),
},
function(err, result) {
if(err) {
return console.error(err);
}

console.log(result);
});

0 comments on commit 38737f9

Please sign in to comment.