1.0.4 • Published 20 days ago

yyl-copy-webpack-plugin v1.0.4

Weekly downloads
11
License
MIT
Repository
github
Last release
20 days 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.4

20 days ago

1.0.3

20 days ago

1.0.2

21 days ago

1.0.1

22 days ago

1.0.0

23 days ago

0.2.11

12 months ago

0.2.10

1 year ago

0.2.9

1 year ago

0.2.8

1 year ago

0.2.7

1 year ago

0.2.6

1 year ago

0.2.5

1 year ago

0.2.4

1 year ago

0.2.3

1 year ago

0.2.2

1 year ago

0.2.2-beta4

1 year ago

0.2.2-beta3

1 year ago

0.2.2-beta2

1 year ago

0.2.2-beta1

1 year ago

0.1.2-beta1

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago