export function alias_hook(path, module, project_path, aliases, log) { // possibly alias the path const aliased_path = alias(path, aliases) // return if an alias not found if (!aliased_path) { return } // if an alias is found, require() the correct path log.debug(`require("${path}") was called and an alias was found, so aliasing to module path "${aliased_path}"`) // resolve the path to a real filesystem path (resolves `npm link`, etc) const global_path = require_hacker.resolve(aliased_path, module) log.debug(` resolved the path for the aliased module to ${global_path}`) return global_path // const result = require(global_path) // // log.debug(` the path was found`) // return require_hacker.to_javascript_module_source(result) }
requireHacker.resolver(function(pathName, module) { for (let alias in webpackConfig.resolve.alias) { if (pathName === alias || pathName.indexOf(alias + '/') === 0) { pathName = pathName.substring(alias.length); let clientPath = path.join(webpackConfig.resolve.alias[alias], pathName); return requireHacker.resolve(clientPath, module); } } });