Skip to content

bolasblack/module-mapper-webpack-plugin

Repository files navigation

module-mapper-webpack-plugin Build Status Coverage Status

Usage

yarn add module-mapper-webpack-plugin -D
// webpack.config.ts

import { ModuleReplaceWebpackPlugin, replacePath } from 'module-mapper-webpack-plugin'

export default {
  // ...
  plugins: [
    new ModuleReplaceWebpackPlugin({
      async replacer(requestInfo) {
        // modify requestInfo object directly
        requestInfo.request = 'absolute path or path relative to issuer'

        // or return a new partial requestInfo
        return {
          request: 'absolute path or path relative to issuer',
        }

        // for example:
        if (
          !/\/file\.overlay\b/.test(requestInfo.contextInfo.issuer) &&
          /\/file\b/.test(requestInfo.request)
        ) {
          return {
            request: replacePath(
              reqPath =>
                path.resolve(
                  path.resolve(requestInfo.context, reqPath),
                  '../file.overlay.js',
                ),
              d.request,
            ),
          }
        }
        return requestInfo
      },
    } as ModuleReplaceWebpackPlugin.ConstructOptions)
  ],
}

Development

yarn build # build code
yarn watch # build and watch code

About

A webpack plugin to replace module path

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •