1.0.0 • Published 2 years ago

@weekbin/clean-independent-files-plugin v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

NPM version NPM language NPM license

clean-independent-files-plugin

A tool to clean independent files. Useful when refactoring code.

Getting started

To begin, you'll need to install @weekbin/clean-independent-files-plugin:

npm install @weekbin/clean-independent-files-plugin --save-dev

or

yarn add -D @weekbin/clean-independent-files-plugin

Then add the plugin to your webpack config. For example:

webpack.config.js

const { WebpackCleanUndependentFilesPlugin } = require("@weekbin/clean-independent-files-plugin");

module.exports = {
  plugins: [
    new WebpackCleanUndependentFilesPlugin({
      autoDelete: true
    })
  ]
};

And run webpack via your preferred method.

Options

entry

Type: Array<string>

Description: entry of the source code dir. Support muti-entry.

Default: ['./src']

autoDelete

Type: boolean

Description: auto remove independent files when it was set to true. For security reasons, default is false.

Default: false

outputLogs

Type: boolean

Description: if output logs of inpendent files list.

Default: true

outputLogsPath

Type: string

Description: the path of output logs.

Default: ./wcufp.json

exclude

Type: Array<string | RegExp>

Description: Even if the file has no dependencies, it will not be cleaned up.

Default: [/typings/, /.+\.d\.ts/]

externalDependencies

Type: Array<string | RegExp>

Description: external dependencies. In production, modules will be imported by script. Thus external should be set.

Default: []

callback

Type: function(this: WebpackCleanUndependentFilesPlugin, files2Delete: string[]): void | null

Description: custom callback before cleanFiles. Throw Errors internal will interrupted the build.

Default: null

useColor

Type: boolean

Description: if use color of console logs.

Default: true

debug

Type: boolean

Description: open debug mode will show more info in console logs.

Default: false

Examples

const { WebpackCleanUndependentFilesPlugin } = require("@weekbin/clean-independent-files-plugin");

module.exports = {
  plugins: [
    new WebpackCleanUndependentFilesPlugin({
      autoDelete: true,
      exclude: [/[T|t]yping/, /[U|u]til/, /.+\.d\.ts/, 'setProxy.js'],
      externalDependencies: [/myOwnCDNFiles/],
      callback(files){
          console.log(files)
      }
    })
  ]
};