# yyl-copy-webpack-plugin

> 过滤规则使用 [https://www.npmjs.com/package/matcher](matcher) 插件

Latest version **1.0.8** (published 2021-04-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install yyl-copy-webpack-plugin
pnpm add yyl-copy-webpack-plugin
yarn add yyl-copy-webpack-plugin
bun add yyl-copy-webpack-plugin
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.8 |
| Published | 2021-04-13 |
| First published | 2019-10-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 9 |
| Unpacked size | 33.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | liudaojie |
| Maintainers | jackness |

## Links

- npm: https://www.npmjs.com/package/yyl-copy-webpack-plugin
- Repository: https://github.com/jackness1208/yyl-copy-webpack-plugin
- Homepage: https://github.com/jackness1208/yyl-copy-webpack-plugin#readme
- Issues: https://github.com/jackness1208/yyl-copy-webpack-plugin/issues
- npm.io page: https://npm.io/package/yyl-copy-webpack-plugin

## Dependencies (9)

- [chalk](https://npm.io/package/chalk.md) ^4.1.0
- [terser](https://npm.io/package/terser.md) ^5.5.1
- [yyl-fs](https://npm.io/package/yyl-fs.md) ^0.3.3
- [matcher](https://npm.io/package/matcher.md) ^3.0.0
- [tapable](https://npm.io/package/tapable.md) ^2.2.0
- [yyl-util](https://npm.io/package/yyl-util.md) ^2.3.9
- [clean-css](https://npm.io/package/clean-css.md) ^5.0.1
- [@types/clean-css](https://npm.io/package/@types/clean-css.md) ^4.2.3
- [yyl-webpack-plugin-base](https://npm.io/package/yyl-webpack-plugin-base.md) ^0.2.2

## Recent versions

- 1.0.8 (latest) — 2021-04-13
- 1.0.7 — 2021-03-06
- 1.0.6 — 2021-03-04
- 1.0.4 — 2021-02-04
- 1.0.3 — 2021-02-04
- 1.0.2 — 2021-02-03
- 1.0.1 — 2021-02-02
- 1.0.0 — 2021-02-01
- 0.2.11 — 2020-03-09
- 0.2.10 — 2020-02-23
- 0.2.9 — 2020-02-22
- 0.2.8 — 2020-02-22
- 0.2.7 — 2020-02-21
- 0.2.6 — 2020-02-20
- 0.2.5 — 2020-02-20
- … 12 more at https://npm.io/package/yyl-copy-webpack-plugin/versions

## README

# yyl-copy-webpack-plugin

过滤规则使用 [https://www.npmjs.com/package/matcher](matcher) 插件

## USAGE

```javascript
const YylCopyWebpackPlugin = require('yyl-copy-webpack-plugin')

const wConfig = {
  plugins: [
    new YylCopyWebpackPlugin({
      /** 拷贝信息 */
      files: [
        {
          from: 'src/source',
          to: 'dist/assets/source',
          matcher: ['*.html', '!**/.*']
        },
        {
          from: 'src/source',
          to: 'dist/assets/source',
          matcher: ['!*.html', '!**/.*']
        }
      ],
      /** 文件名 默认为 [name]-[hash:8].[ext] */
      filename: '[name]-[hash:8].[ext]',
      /** 是否压缩 */
      minify: true,
      /** log 路径的 相对路径 */
      logBasePath: __dirname,
      /** 基本路径, 会用于 resolve files 里面的路径 */
      basePath: __dirname
    })
  ]
}
```

## hooks

```javascript
let YylCopyWebpackPlugin
try {
  YylCopyWebpackPlugin = require('yyl-copy-webpack-plugin')
} catch (e) {
  if (!(e instanceof Error) || e.code !== 'MODULE_NOT_FOUND') {
    throw e
  }
}

const PLUGIN_NAME = 'your_plugin'
class ExtPlugin {
  apply(compiler) {
    const IPlugin = YylCopyWebpackPlugin
    if (IPlugin) {
      compiler.hooks.compilation.tap(IPlugin.getName(), (compilation) => {
        IPlugin.getHooks(compilation).beforeCopy.tapAsync(PLUGIN_NAME, (obj, done) => {
          console.log('hooks.beforeConcat(obj, done)', 'obj:', obj)
          done(null, obj)
        })
        IPlugin.getHooks(compilation).afterCopy.tapAsync(PLUGIN_NAME, (obj, done) => {
          console.log('hooks.afterConcat(obj, done)', 'obj:', obj)
          done(null, obj)
        })
      })
    }
  }
}
```

## ts

```typescript
/// <reference types="node" />
import { Compilation, Compiler } from 'webpack'
import {
  AssetsInfo,
  YylWebpackPluginBaseOption,
  YylWebpackPluginBase
} from 'yyl-webpack-plugin-base'
export interface AssetsSource {
  size(): number
  map(options?: any): Object
  sourceAndMap(
    options?: any
  ): {
    source: string | Buffer
    map: Object
  }
  updateHash(hash: any): void
  source(): string | Buffer
  buffer(): Buffer
}
export declare type FileInfo = Required<AssetsInfo>
export interface CopyInfo {
  /** 原地址 */
  from: string
  /** 目标地址 */
  to: string
  /** 沿用 matcher 规则 */
  matcher?: string[]
  /** 文件名 默认为 [name]-[hash:8].[ext] */
  filename?: string
}
export interface YylCopyWebpackPluginOption extends Pick<YylWebpackPluginBaseOption, 'context'> {
  /** 拷贝信息 */
  files?: CopyInfo[]
  /** 是否压缩 */
  minify?: boolean
  /** 压缩是否支持 ie8 默认 false */
  ie8?: boolean
  /** log 路径的 相对路径 */
  logContext?: string
}
export default class YylCopyWebpackPlugin extends YylWebpackPluginBase {
  static getHooks(compilation: Compilation): any
  static getName(): string
  option: Required<YylCopyWebpackPluginOption>
  constructor(option?: YylCopyWebpackPluginOption)
  formatSource(fileInfo: FileInfo): Promise<FileInfo>
  apply(compiler: Compiler): Promise<void>
}
```

---
_Source: https://npm.io/package/yyl-copy-webpack-plugin · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
