1.0.0 • Published 2 years ago

module-mapper-webpack-plugin v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

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