GithubHelp home page GithubHelp logo

vijar / strip-loader Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yahooarchive/strip-loader

0.0 2.0 0.0 19 KB

Webpack loader to strip arbitrary functions out of your production code.

License: Other

JavaScript 100.00%

strip-loader's Introduction

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.

strip-loader's People

Contributors

gpbl avatar tikotzky avatar vijar avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.