Path Override Webpack Plugin

raw JSON →
0.1.2 verified Sat Apr 25 auth: no javascript

A Webpack plugin that allows overriding module import paths with an external set of matching files. Use it to replace modules dynamically based on a regex pattern, useful for theming or skinning complex applications. Current stable version is 0.1.2, released infrequently with minimal updates. Key differentiator: unlike Webpack's native alias which requires exact paths, this plugin conditionally overrides based on file existence, falling back to the original if no override file is found. Compatible with Webpack 4.x. Not recommended for new projects; consider using Webpack's resolve.alias or resolve.plugins instead.

error Error: Path must be a string. Received undefined
cause Missing or invalid pathReplacement argument.
fix
Ensure the second argument to PathOverridePlugin constructor is a valid string path.
error TypeError: PathOverridePlugin is not a constructor
cause Incorrect import: using named import instead of default import in ESM or missing .default in CommonJS.
fix
Use import PathOverridePlugin from 'path-override-webpack-plugin' (ESM) or const PathOverridePlugin = require('path-override-webpack-plugin').default (CommonJS).
error Cannot find module 'path-override-webpack-plugin'
cause Package not installed or missing from node_modules.
fix
Run npm install --save-dev path-override-webpack-plugin and ensure it's in your package.json.
gotcha The plugin only works with Webpack 4.x; not tested with Webpack 5.
fix Use Webpack 4 or consider alternative such as webpack resolve.alias.
gotcha The pathReplacement is relative to the project root, not the module being overridden.
fix Provide an absolute path to avoid confusion: new PathOverridePlugin(/pattern/, path.resolve(__dirname, 'override-folder'))
gotcha Only supports RegExp for pattern matching; string paths or globs are not accepted.
fix If you need string matching, convert to RegExp manually: new RegExp('^app/view')
deprecated No active maintenance since 2018; repository archived or unmaintained.
fix Migrate to Webpack's resolve.alias or resolve.plugins (e.g., NormalModuleReplacementPlugin).
npm install path-override-webpack-plugin
yarn add path-override-webpack-plugin
pnpm add path-override-webpack-plugin

Create a webpack configuration that overrides module paths matching 'app/view' with files from an external package.

const PathOverridePlugin = require('path-override-webpack-plugin');

module.exports = {
  mode: 'production',
  entry: './src/index.js',
  output: {
    path: __dirname + '/dist',
    filename: 'bundle.js'
  },
  plugins: [
    new PathOverridePlugin(
      /^app\/view/,
      './node_modules/SomeExternalSkin/src'
    )
  ]
};