Skip to content

fayfang/hashwatcher-webpack-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hashwatcher-webpack-plugin

用于webpack打包到生产环境后,客户端无刷新的情况下通知用户版本变更信息。依赖createEvent,用addEventListener接收事件。

install

  npm install hashwatcher-webpack-plugin --save-dev

options

key type default description
duration Number 60000 interval duration for getting jsonRender.js
path String '' 'webpackHashWatcher.js' output path
hashPath hashPath '' 'jsonRender.js' output path

example

webpack.config.js

const HtmlWebpackPlugin = require('html-webpack-plugin')
const HashwatcherWebpackPlugin = require('hashwatcher-webpack-plugin')

module.exports = {
  entry: {
    app: './src/index.js'
  },
  plugins: [
    new HtmlWebpackPlugin({
      filename: 'index.html',
      template: 'index.html',
      inject: true
    }),
    new HashwatcherWebpackPlugin({
      duration: 10000
    })
  ]
}

index.js

// wehn then hash change, it will receive a 'webpackHashChange' event
document.addEventListener('webpackHashChange', (e) => {
  console.log(e.diffArr)
  alert('检测到系统已更新,请刷新页面更新系统')
})

About

webpack plugin for watching chunkHash change

Resources

Stars

Watchers

Forks

Packages

No packages published