webpack-strip-block

Webpack plugin to strip blocks of code that's only intended for development purposes

MIT 6 个版本
安装
npm install webpack-strip-block
yarn add webpack-strip-block
pnpm add webpack-strip-block
bun add webpack-strip-block
README

Webpack Strip Block

Webpack loader to strip blocks of code marked by special comment tags. Useful for removing code that you don't want in your production webpack bundle (e.g. verbose console warnings, etc).

Example:

In your client js source files:


var makeFoo(bar, baz) {
    // The following code will be stripped with our webpack loader
    /* develblock:start */
    if (bar instanceof Bar !== true) {
        throw new Error('makeFoo: bar param is required and must be instance of Bar');
    }
    /* develblock:end */

    // This code would remain
    return new Foo(bar, baz);
}

In your webpack config, specify the loader:

module.exports = {
  rules: [
    {
      test: /\.js$/,
      enforce: 'pre',
      exclude: /(node_modules|bower_components|\.spec\.js)/,
      use: [
        {
          loader: 'webpack-strip-block'
        }
      ]
    }
  ]
};

If you want to use custom comment tags to mark the start and end of the block to strip from your code, you can add options for "start" and "end" like this:

module.exports = {
  rules: [
    {
      test: /\.js$/,
      enforce: 'pre',
      exclude: /(node_modules|bower_components|\.spec\.js)/,
      use: [
        {
          loader: 'webpack-strip-block',
          options: {
            start: 'DEV-START',
            end: 'DEV-END'
          }
        }
      ]
    }
  ]
};
版本列表
0.3.0 2020-08-21
0.2.0 2017-05-05
0.1.1 2017-04-21
0.1.0 2016-07-16
0.0.3 2016-06-18
0.0.1 2014-07-12