New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

mimic-webpack

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mimic-webpack

Mimics a webpack config's filename extensions, aliases, and loaders inside of the current node process

latest
Source
npmnpm
Version
1.5.4
Version published
Maintainers
1
Created
Source

mimic-webpack

Mimics a webpack config's filename extensions, aliases, and loaders inside of the current node process.

You might want to mimic.install():

  • instead of bundling your specs with webpack.
  • before using linter rules like eslint-plugin-require-path-exists.
  • when performing universal rendering with code you also plan to bundle with webpack.

installation

npm install mimic-webpack

usage

In your entry file:

var Mimic = require('mimic-webpack');
new Mimic({
    webpackConfig: { // pass your webpack config here
        resolve: {
            extensions: ['.foo'],
            alias: {
                myModule: 'theirModule'
            }
        },
        module: {
            loaders: [{
                test: /\.foo$/,
                loader: 'foo-loader'
            }]
        }
    }
}).install();

myModule.foo:

// code to be processed with foo-loader

Now, anywhere in your project, you can do this:

require('theirModule');

In the above example:

  • theirModule is aliased to myModule due to resolve.alias
  • The .foo extension is inferred due to `resolve.extensions.
  • The module is processed with foo-loader because of module.loaders

api

  • Mimic.prototype.install - configures require in the current node process to behave according to the webpack config specified by options.webpackConfig passed to the constructor. Returns the current instance.
  • Mimic.prototype.uninstall - un-does what Mimic.prototype.install did. Returns the current instance.
  • Mimic.restore - restores configuration to the way it was before Mimic was required in.

known issues

Paths that were resolved using custom properties in require.extensions will continue to resolve the same even after Mimic.restore or Mimic.prototype.uninstall have been called.

myMimic.uninstall();
require.resolve('theirModule'); // still resolves to myModule.foo.

current limitations

  • Loaders must be specified in the webpack config. Loaders specified on the require path will not work
  • install and uninstall can only be run once per instance.

FAQs

Package last updated on 20 Aug 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts