Estus Flask
Estus Flask

Reputation: 222474

Resolve the module loaded by plugin in Webpack config

The following example will work only if some-module module is Node module, and won't work for modules loaded by Webpack plugin.

How can Webpack's own logic (enhanced-resolve) be used to resolve module paths in config?

In my case it was bower-webpack-plugin, but I guess this should work in the same way with any ResolverPlugin

var BowerWebpackPlugin = require("bower-webpack-plugin");
module.exports = {
    ...
    module: {
        plugins: [new BowerWebpackPlugin()],
        loaders: [
            {
                // this won't work
                test: require.resolve("some-bower-module")
                loader: "imports?this=>window"
            }
        ]
};

Upvotes: 7

Views: 1509

Answers (1)

matpie
matpie

Reputation: 17512

require.resolve inside webpack.config.js is resolved by Node and not Webpack's resolver. You can use require("path").resolve("path/to/bower/module") to get the full path to your Bower module.

Upvotes: 1

Related Questions