Skip to content

KaiWinding/modify-webpack-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

modify-webpack-plugin

a webpack plugin modify any file with new string befor webpack building
(for webpack v4)

Install

# use npm
npm install --save-dev modify-webpack-plugin
# use yarn
yarn add modify-webpack-plugin -D

Usage

// webpack.config.js
const ModifyWebpackPlugin = require("modify-webpack-plugin")

module.exports = {
  plugins: [
    new ModifyWebpackPlugin({
      include: [/\.js$/]
      exclude: ['node_modules']
      patterns: [{
        reg: /console\.log\(.*\)/g
        newStr: ''
      }]
    }),
  ]
}

This case will remove all console.log in the required *.js modules

⚠️ if you don't give a argument for include, this plugin wil modify every required file even css, jpg or anyother type. So set the include !

Options

new ModifyWebpackPlugin(options: object)
Name Type Description
include String|RegExp|Array<String|RegExp> If multiple conditions are provided, matching any condition will include & scan the filepath to modify target files.
exclude String|RegExp|Array<String|RegExp> If multiple conditions are provided, matching any condition will exclude the filepath, which prevents any alterations. By default, nothing is excluded!
patterns Array<{reg: String|RegExp, newStr: string}> An array of RegExp pattern definitions. Each definition is an object with reg and newStr keys.

About

a webpack plugin that can modify anything

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published