Socket
Socket
Sign inDemoInstall

empty-module-loader

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    empty-module-loader

A webpack loader that replaces module with empty function.


Version published
Weekly downloads
83
decreased by-14.43%
Maintainers
1
Install size
4.21 kB
Created
Weekly downloads
 

Readme

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

FAQs

Last updated on 10 Oct 2018

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