Skip to content

Instantly share code, notes, and snippets.

@sebastiandeutsch
Created August 11, 2016 21:32
Show Gist options
  • Save sebastiandeutsch/9e260a6f88518f88a57367df8c64e4a9 to your computer and use it in GitHub Desktop.
Save sebastiandeutsch/9e260a6f88518f88a57367df8c64e4a9 to your computer and use it in GitHub Desktop.
Not working - just a test
var path = require("path");
var forEachBail = require("enhanced-resolve/lib/forEachBail");
var createInnerCallback = require("enhanced-resolve/lib/createInnerCallback");
var assign = require("object-assign");
module.exports = DirectoryNamedWebpackPlugin;
function DirectoryNamedWebpackPlugin(honorIndex) {
this.honorIndex = !!honorIndex;
}
DirectoryNamedWebpackPlugin.prototype.apply = function (resolver) {
var honorIndex = this.honorIndex;
var directories = this.directories;
var target = this.target;
resolver.plugin("directory", function(request, callback) {
var fs = this.fileSystem;
var topLevelCallback = callback;
var dirPath = request.path;
var dirName = dirPath.substr(dirPath.lastIndexOf(path.sep) + path.sep.length);
fs.stat(dirPath, function(err, stat) {
if (err || !stat || !stat.isDirectory()) {
callback.log && callback.log(dirPath + " doesn't exist or is not a directory (directory named)");
return callback();
}
// we have a directory
forEachBail(
honorIndex ? ["index", dirName] : [dirName],
function (file, innerCallback) {
// I'm able to append the directory path with the name to get a new path
console.log(file);
var newPath = path.join(dirPath, file);
// I don't know how to form the request for a file
var obj = assign({}, request, {
path: newPath
});
var message = "looking for modules in " + dirPath;
console.log(newPath);
return resolver.doResolve("file", obj, message, createInnerCallback(callback, topLevelCallback));
},
callback
);
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment