How can I share webpack.config snippets between projects?

Viewed 2030

I have several webpack configurations with very similar webpack.config files. I like to put webpack.config parts in a shared module that (I include the shared module with "npm link"), but that doesn't work as can't find dependencies, like "webpack" as it's the first dependency it encounters.

17 07 2017 14:49:32.694:ERROR [config]: Invalid config file!
  Error: Cannot find module 'webpack'
    at Function.Module._resolveFilename (module.js:470:15)

First webpack.config lines:

const webpack = require('webpack');
const path = require('path');
....

How can I instruct webpack to search for the included dependences in node_modules of the project that includes the webpack.config?

I tried to realise this by adding the following to the resolve webpack.config section, but that doesn't help:

modules: [path.resolve(__dirname, "node_modules"), "node_modules"]

I think it's not used by the webpack.config itself but by the JS code that is processed by webpack.config.

1 Answers
Related