empty-module-loader
v1.0.0
Published
A webpack loader that replaces module with empty function.
Downloads
213
Maintainers
Readme
npm install --save-dev empty-module-loader
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.
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)
}
npm init -y
npm install webpack webpack-cli uglifyjs-webpack-plugin --save-dev
npx webpack --config webpack.config.js
/************************************************************************/
/******/([
/* 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")
/***/}
/******/]);