A tool to clean independent files. Useful when refactoring code.
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.
Type: Array<string>
Description: entry of the source code dir. Support muti-entry.
Default: ['./src']
Type: boolean
Description: auto remove independent files when it was set to true
. For security reasons, default is false
.
Default: false
Type: boolean
Description: if output logs of inpendent files list.
Default: true
Type: string
Description: the path of output logs.
Default: ./wcufp.json
Type: Array<string | RegExp>
Description: Even if the file has no dependencies, it will not be cleaned up.
Default: [/typings/, /.+\.d\.ts/]
Type: Array<string | RegExp>
Description: external dependencies. In production, modules will be imported by script. Thus external should be set.
Default: []
Type: function(this: WebpackCleanUndependentFilesPlugin, files2Delete: string[]): void | null
Description: custom callback before cleanFiles. Throw Errors internal will interrupted the build.
Default: null
Type: boolean
Description: if use color of console logs.
Default: true
Type: boolean
Description: open debug mode will show more info in console logs.
Default: false
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)
}
})
]
};
You can also use defaultConfig from package
const defaultConfig = {
entry: ['./src'],
exclude: [/[t|T]yping/, /.+\.d\.ts/, /[u|U]til/, /[p|P]ublic/]
}
const { defaultConfig } = require("@weekbin/clean-independent-files-plugin");
module.exports = {
plugins: [
new WebpackCleanUndependentFilesPlugin(defaultConfig)
]
};