webpack_up_version.js 651 B

1234567891011121314151617181920212223242526272829303132
  1. /**
  2. * webpack_up_version.js
  3. */
  4. 'use strict'
  5. const updateVersion = require('./updateVersion')
  6. const STEP = 0.1
  7. class UpVersionWebpackPlugin {
  8. constructor (options) {
  9. this.options = options
  10. this._score = -1
  11. }
  12. apply (compiler) {
  13. compiler.plugin('compile', () => {
  14. if (this._score >= 0 && this._score < 1) {
  15. // 防止更新太频繁
  16. this._score += STEP
  17. return
  18. }
  19. console.log('~~~~~~~~~~~~~~~~~~~~~~ update version ~~~~~~~~~~~~~~~~~~~~~~')
  20. let {fn, packages} = this.options
  21. updateVersion(fn, packages)
  22. this._score = 0
  23. })
  24. }
  25. }
  26. module.exports = UpVersionWebpackPlugin