This repository has been archived by the owner. It is now read-only.
Webpack loader to strip arbitrary functions out of your production code.
Switch branches/tags
Nothing to show
Clone or download
Latest commit 048de47 May 15, 2017
Permalink
Failed to load latest commit information.
lib corrected code style Jan 29, 2016
tests corrected code style Jan 29, 2016
.coveralls.yml badges, travis-ci, coveralls Jan 21, 2015
.gitignore 0.1.0 Jan 20, 2015
.npmignore 0.1.0 Jan 20, 2015
.travis.yml badges, travis-ci, coveralls Jan 21, 2015
CONTRIBUTING.md Rename to strip-loader Jan 21, 2015
LICENSE.md 0.1.0 Jan 20, 2015
README.md Deprecate strip-loader May 15, 2017
package.json 0.1.2 Jan 30, 2016

README.md

This Project Is Deprecated

There have been a lot of long standing issues that haven't been addressed and we haven't had the time to dedicate to this library. If I were to restart this project today, it would probably be a codemod script using Facebook's jscodeshift. The regex based approach in this loader only works for very basic use cases.

The most common use case is when trying to strip console.log from your code. You can actually do this without using this loader at all. You can use uglifyjs's drop_console option. Here is what that would look like in a webpack plugin:

new webpack.optimize.UglifyJsPlugin({
    compress: {
        drop_console: true
    }
})

Strip Loader

npm version Build Status Dependency Status devDependency Status Coverage Status

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.

Install

npm install --save-dev strip-loader

Usage

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';
};

Single function

In your webpack config:

{
    module: {
        loaders: [
            { test: /\.js$/, loader: "strip-loader?strip[]=debug" }
        ]
    }
};

Multiple functions

In your webpack config:

{
    module: {
        loaders: [
            { test: /\.js$/, loader: "strip-loader?strip[]=debug,strip[]=console.log" }
        ]
    }
};

Use as library

In your webpack config:

var WebpackStrip = require('strip-loader');

var webpackConfig = {
    module: {
        loaders: [
            { test: /\.js$/, loader: WebpackStrip.loader('debug', 'console.log') }
        ]
    }
};

Replace unused module

So far we've removed the calls to the debug function, but your app still requires the debug module in the final bundle. Use the NormalModuleReplacementPlugin to replace it with an empty function:

// webpack config
{
    plugins: [
        new webpack.NormalModuleReplacementPlugin(/debug/, process.cwd() + '/emptyDebug.js'),
    ]
}

// emptyDebug.js
module.exports = function() { return new Function(); };

License

This software is free to use under the Yahoo! Inc. BSD license. See the LICENSE file for license text and copyright information.