Hi guys.
I have a problem with https://github.com/webpack/jade-loader. It always return a function, but i want this loader always return a string. So that I intend to write a custom loader that return a string from jade-loader template function. It is very simple, but how can i use it ?
module.exports = function(source) {
console.log(source);
return source();
};
I want to use like that “jade-loader -> template function -> jade-to-html -> return string -> ng-cache -> get this string for angular template-cache”.
var jadeToHtmlLoader = require('./jade-to-html-loader');
//How can i use like this. Thanks !
{test: /\.jade/, loader: "jade-loader!jade-to-html-loader!ng-cache?prefix=[dir]/[dir]"},
@chenerlang666
You can use the
resolveLoader.alias
config option which works the same way thatresolve.alias
works.For example:
In addition, they show a relative loader in the introduction to loaders
Since all the pieces to solve this puzzle are not here or on the linked pages:
Now we need the webpack 2 compatible version of these scripts, to allow custom loader not on NPM.
I paste my custom loader used in Webpack 2 for anyone interested in future:
The
readme-loader
is very similar toraw-loader
and exports an object with both parsed and raw markdown. The raw-loader is a very nice and easy to understand example of loader.This also works:
@adriancmiranda Using it the way you are describing does not give you the proper context object (👍
this
). I used it like @jiayihu was suggesting and it works nicely