1.0.7 • Published 23 days ago

yyl-concat-webpack-plugin v1.0.7

Weekly downloads
12
License
MIT
Repository
github
Last release
23 days ago

yyl-concat-webpack-plugin

USAGE

plugin

const YylConcatWebpackPlugin = require('yyl-concat-webpack-plugin')

const wConfig = {
  plugins: [
    new YylConcatWebpackPlugin({
      fileMap: {
        'dist/assets/js/vendors.js': ['src/js/a.js', 'src/js/b.js']
      },
      uglify: false,
      logBasePath: process.cwd(),
      fileName: '[name]-[hash:8].[ext]'
    })
  ]
}

hooks

example

let YylCopyWebpackPlugin
try {
  YylCopyWebpackPlugin = require('yyl-copy-webpack-plugin')
} catch (er) {
  if (!(er instanceof Error) || er.code !== 'MODULE_NOT_FOUND') {
    printError(er)
  }
}
class YourPlugin {
  render(src, source) {
    return source
  }
  apply(compiler) {
    if (YylCopyWebpackPlugin) {
      compiler.hooks.compilation.tap(YylCopyWebpackPlugin.getName(), (compilation) => {
        // + beforeCopy
        YylCopyWebpackPlugin.getHooks(compilation).beforeCopy.tapAsync(PLUGIN_NAME, (obj, done) => {
          obj.source = this.render({
            src: obj.src,
            source: obj.source
          })
          done(null, obj)
        })
        // - beforeCopy

        //+ afterCopy
        YylCopyWebpackPlugin.getHooks(compilation).afterCopy.tapAsync(PLUGIN_NAME, (obj, done) => {
          obj.source = this.render({
            src: obj.src,
            source: obj.source
          })
          done(null, obj)
        })
        //- afterCopy
      })
    }
  }
}

hooks

let YylConcatWebpackPlugin
try {
  YylConcatWebpackPlugin = require('yyl-concat-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 = YylConcatWebpackPlugin
    if (IPlugin) {
      compiler.hooks.compilation.tap(IPlugin.getName(), (compilation) => {
        IPlugin.getHooks(compilation).beforeConcat.tapAsync(PLUGIN_NAME, (obj, done) => {
          console.log('hooks.beforeConcat(obj, done)', 'obj:', obj)
          done(null, obj)
        })
        IPlugin.getHooks(compilation).afterConcat.tapAsync(PLUGIN_NAME, (obj, done) => {
          console.log('hooks.afterConcat(obj, done)', 'obj:', obj)
          done(null, obj)
        })
      })
    }
  }
}

ts

文档

1.0.7

23 days ago

1.0.6

23 days ago

1.0.5

23 days ago

1.0.4

24 days ago

1.0.2

25 days ago

1.0.1

25 days ago

1.0.0

26 days ago

1.0.3

25 days ago

0.2.10

12 months ago

0.2.9

12 months 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.2-beta3

1 year ago

0.2.2

1 year ago

0.2.2-beta2

1 year ago

0.2.2-beta1

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.0

1 year ago