Socket
Socket
Sign inDemoInstall

@berhalak/dedup-resolve-webpack-plugin

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @berhalak/dedup-resolve-webpack-plugin

Webpack plugin that resolves copies of the same module in different locations to a single path.


Version published
Maintainers
1
Install size
5.75 kB
Created

Readme

Source

dedup-resolve-webpack-plugin

Resolves copies of the same module in different locations to a single path.

This plugin allows to solve the issue descrived at https://github.com/webpack/webpack/issues/5593. When you use nice libA in your project, and depA and depB also use this cool libA then you will have 3 copies of libA in your resulting bundle. No uglification, tree shaking and other cool features will help you to avoid code duplication.

projectA
- node_modules
-- libA
-- depA
---- node_modules/libA
-- depB
---- node_modules/libA 

This plugin will check the dependecies, their versions and will use only one (first) location of libA.

Usage:

  1. Install the plugin as a development dependency:

    Yarn: yarn add @berhalak/dedup-resolve-webpack-plugin -D

    NPM: npm install @berhalak/dedup-resolve-webpack-plugin -D

  2. Require a plugin in webpack configuration file and register it as resolve plugin.

var webpack = require('webpack');
var DedupPlugin = require('dedup-resolve-webpack-plugin');

module.exports = {
  entry: [
    './src/index.js'
  ],
  module: {
    loaders: [{
      test: /\.js?$/,
      exclude: /node_modules/,
      loader: 'babel-loader'
    }]
  },
  resolve: {
    extensions: ['.js'],
    plugins: [new DedupPlugin({ path: path.resolve(__dirname, "node_modules") })],
  },
  plugins: [/*DO NOT ADD the plugin here. Add it to resolve/plugins section.*/]
}
  1. If you enabled verbose flag then you will see the output simmilar to the following. It means that both a and b will use debug library from parent location.
[Dedup]: d:\Projects\webpack-dedupe\node_modules\b\node_modules\debug
      => d:\Projects\webpack-dedupe\node_modules\debug
[Dedup]: d:\Projects\webpack-dedupe\node_modules\a\node_modules\debug
      => d:\Projects\webpack-dedupe\node_modules\debug
  1. Adding path options, that will help with monorepo. It will keep node_modules under root path.

FAQs

Last updated on 29 Mar 2020

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc