1.0.8 • Published 3 years ago

yyl-copy-webpack-plugin v1.0.8

Weekly downloads
128
License
MIT
Repository
github
Last release
3 years ago

yyl-copy-webpack-plugin

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

USAGE

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

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

/// <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>
}
1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.2.11

4 years ago

0.2.10

4 years ago

0.2.9

4 years ago

0.2.8

4 years ago

0.2.7

4 years ago

0.2.6

4 years ago

0.2.5

4 years ago

0.2.4

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.2-beta4

4 years ago

0.2.2-beta3

4 years ago

0.2.2-beta2

4 years ago

0.2.2-beta1

4 years ago

0.1.2-beta1

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.1

5 years ago

0.1.0

5 years ago