-
Notifications
You must be signed in to change notification settings - Fork 376
/
Copy pathdirectory-loader.js
58 lines (51 loc) · 1.99 KB
/
directory-loader.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
var loaderUtils = require("loader-utils");
var path = require("path");
module.exports = DirectoryLoaderPlugin;
function DirectoryLoaderPlugin(paths) {
this.paths = paths;
}
DirectoryLoaderPlugin.prototype.apply = function (resolver) {
var optPaths = this.paths;
console.log('A' + optPaths);
resolver.plugin("directory", function (request, callback) {
var dirPath = this.join(request.path, request.request);
var dirName = dirPath.substr(dirPath.lastIndexOf(path.sep) + path.sep.length);
if (optPaths && optPaths.indexOf(dirPath) >= 0) {
this.fileSystem.stat(dirPath, function (err, stat) {
if (err || !stat || !stat.isDirectory()) {
callback.log && callback.log(request.path + " doesn't exist or is not a directory (directory named)");
return callback();
}
try {
request.resolved = true;
callback.log = function() {
console.log(arguments);
};
console.log(callback);
return callback(null, null);
} catch (e) {
console.error(e);
throw e;
}
}.bind(this));
}
//} else {
callback();
//}
});
};
DirectoryLoaderPlugin.loader = function(content) {
//this.cacheable && this.cacheable();
//if(!this.emitFile) throw new Error("emitFile is required from module system");
//var query = loaderUtils.parseQuery(this.query);
//var url = loaderUtils.interpolateName(this, query.name || "[hash].[ext]", {
// context: query.context || this.options.context,
// content: content,
// regExp: query.regExp
//});
//this.emitFile(url, content);
//return "module.exports = __webpack_public_path__ + " + JSON.stringify(url) + ";";
console.log('blah');
return ' hello ';
};
DirectoryLoaderPlugin.loader.raw = true;