🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

empty-module-loader

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

empty-module-loader

A webpack loader that replaces module with empty function.

1.0.0
latest
Source
npm
Version published
Maintainers
1
Created
Source

Empty Module Loader

A webpack loader that replaces module with empty function.

npm deps Npm Downloads Total

Install

npm install --save-dev empty-module-loader

Usage

webpack.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /path-to-match-module/,
        loader: 'empty-module-loader'
      }
    ]
  }
}

That is it! All the related codes should be removed in production.

Example

This config is for demonstration only.

webpack.config.js

const path = require('path')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')

module.exports = {
  entry: './src/index.js',
  output: {
    filename: 'main.js',
    path: path.resolve(__dirname, 'dist'),
  },
  module: {
    rules: [
      {
        test: /debug/,
        loader: require.resolve('empty-module-loader')
      },
    ],
  },
  optimization: {
    minimizer: [
      new UglifyJsPlugin({
        uglifyOptions: {
          warnings: false,
          mangle: false,
          ie8: false,
          output: {
            preserve_line: true,
            comments: true,
            indent_level: 2,
          },
        },
      }),
    ],
  },
}

src/index.js

import debug from './debug'

console.log('normal code')

debug('booting %o', 3)

console.log('normal code')

src/debug.js

export default function debug (...args) {
  console.log('debug:', ...args)
}

Run Commands At Project Root

npm init -y
npm install webpack webpack-cli uglifyjs-webpack-plugin --save-dev
npx webpack --config webpack.config.js

Output

/************************************************************************/
/******/([
/* 0 */
/***/function(module,__webpack_exports__,__webpack_require__){

"use strict"
;__webpack_require__.r(__webpack_exports__);// removed by empty-module-loader
// CONCATENATED MODULE: ./src/index.js





console.log("normal code"),



console.log("normal code")
/***/}
/******/]);

Keywords

webpack

FAQs

Package last updated on 10 Oct 2018

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