Empty Module Loader
A webpack loader that replaces module with empty function.
Install
npm install --save-dev empty-module-loader
Usage
webpack.config.js
moduleexports = 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 = const UglifyJsPlugin = moduleexports = entry: './src/index.js' output: filename: 'main.js' path: path module: rules: test: /debug/ loader: require optimization: minimizer: uglifyOptions: warnings: false mangle: false ie8: false output: preserve_line: true comments: true indent_level: 2
src/index.js
console console
src/debug.js
{ console}
Run Commands At Project Root
npm init -ynpm install webpack webpack-cli uglifyjs-webpack-plugin --save-devnpx webpack --config webpack.config.js
Output
/************************************************************************//******//* 0 *//***/{ "use strict";__webpack_require__;// removed by empty-module-loader// CONCATENATED MODULE: ./src/index.js console console/***/}/******/;