If a loader uses external resources, such as when reading from a filesystem, the loader must indicate this. This information is used to invalidate "cacheable" loaders and recompile them in watch mode. What follows is a brief example of how to accomplish this, using the addDependency method inside of loader.js:
import path from 'path';
export default function(source) {
var callback = this.async();
var headerPath = path.resolve('header.js');
this.addDependency(headerPath);
fs.readFile(headerPath, 'utf-8', function(err, header) {
if(err) return callback(err);
callback(null, header + ' ' + source);
});
}
There are some differences between the loader and modular dependencies. Let's now discuss the latter.