remove-function-loader
The Problem
We can run ifdef as a webpack loader, but it requires us to write additional code to parse. What if we have analytics, debugging, or development functions/methods being called that we simply want removed in production?
The Solution
remove-function-loader reads your specficied files and removes function called (not definitions) from the file during a webpack build. It retains the function in the source code but the output from webpack has absolutely no calls to the specified functions.
Install
npm install --save-dev remove-function-loader
Setup
note: use Babel before running this loader
module: {
rules: [
{
test: /\.js?$/, // Check for all js fi
exclude: /(node_modules|bower_components)
use: {
loader: path.resolve('./src/loader.js'),
options: {
functions: ['hello', 'ttt.hello'],
removeDefinitions: false
}
}
},
{
test: /\.js?$/, // Check for all js files
exclude: /(node_modules|bower_components)/,
use: [{
loader: 'babel-loader',
options: {
presets: ['env']
}
}]
}]
}
},
To Do:
- Add support for removing function definitions
- Add more examples