Simple Webpack loader to strip custom functions from your code. This can be useful if you want to use debug statements while developing your app but don't want this info exposed in your production code.
npm install --save-dev strip-loader
In your client js source files:
var debug = require('debug')('MyFile');
var makeFoo = function () {
// The following two lines of code will be stripped with our webpack loader
debug('makeFoo called');
debug('makeFoo args', arguments);
// This code would remain
return 'Foo';
};
In your webpack config:
{
module: {
loaders: [
{ test: /\.js$/, loader: "strip-loader?strip[]=debug" }
]
}
};
In your webpack config:
{
module: {
loaders: [
{ test: /\.js$/, loader: "strip-loader?strip[]=debug,strip[]=console.log" }
]
}
};
In your webpack config:
var WebpackStrip = require('strip-loader');
var webpackConfig = {
module: {
loaders: [
{ test: /\.js$/, loader: WebpackStrip.loader('debug', 'console.log') }
]
}
};
So far we've removed the calls to the debug function, but webpack will still include the debug
module in the final bundle. Use the IgnorePlugin
{
plugins: [
new webpack.IgnorePlugin(/debug/)
]
}
This software is free to use under the Yahoo! Inc. BSD license. See the LICENSE file for license text and copyright information.