1

I've implemented custom resolver according to this answer. I've got entry.js file which requires zuka/core module like this:

require('zuka/core');

document.write("It works.");

I have the following webpack.config.js file:

const MyConventionResolver = require('./MyConventionResolver');
const webpack = require('webpack');


module.exports = {
    entry: "./entry.js",
    output: {
        path: __dirname + "/dist",
        filename: "bundle.js"
    },
    plugins: [
        new webpack.ResolverPlugin([
            new MyConventionResolver()
        ])
    ]
};

The problem is that I don't get request.path that contains zuka/core inside resolver.plugin('module', function(request, callback) { function, however I do get other paths, so my plugin is working. Why don't I get zuka/core? Webpack also emits error that zuka/core is not found.

Community
  • 1
  • 1
Olena Horal
  • 1,166
  • 3
  • 11
  • 26

1 Answers1

1

You shouldn't be checking request.path, instead check for request.request. Each plugin receives the request object with the following properties:

path: path to a file where a require call is processed

request: module name (what's inside require)

For example, you have the following structure:

workdir
|
|-another
        |
        |-entry.js

And inside entry.js you have the following:

require("zuka/core");

So with this configuration you'll have request.path equal to workdir/another and request.request equal to zuka/core.

Community
  • 1
  • 1
Max Koretskyi
  • 101,079
  • 60
  • 333
  • 488