Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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"
            }
        ]
};
like image 492
Estus Flask Avatar asked Jun 27 '15 22:06

Estus Flask


1 Answers

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.

like image 129
matpie Avatar answered Oct 26 '22 00:10

matpie