<file_sep>// npx webpack --config webpack.config.js
// 通过向 npm run build 命令和你的参数之间添加两个中横线，可以将自定义参数传递给 webpack，例如：npm run build -- --colors。
const path = require('path');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin')

module.exports = {
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'index.js',
    library: 'HtmlStrReplace', // 暴露library
    libraryTarget: 'umd' //libraryTarget 控制 library 如何以不同方式暴露的选项(var this window umd)。
  },
  plugins: [
    // tree shaking
    new UglifyJSPlugin()
  ]
}
<file_sep># res-cash for xhr web cache
### res-cash install
```bash
  npm install cache-for-res --save
```
### res-cash for ES6
```js
  
  import ResCache from 'cache-for-res'

  const cacheList = new ResCache()
  console.log(cacheList)

```
### update: 
  ```js
  npm login
  // 用户名:hansin
  // 密码:****
  // 邮箱:<EMAIL> 
  npm version patch 
  npm publish
  ```
<file_sep>// 调用
/*
** @params
** path: 请求的路径
** preload: 请求的参数
** cachetype: 'no'[本次请求不走缓存过滤] ‘str’[同一个路径缓存一条] ‘arr’[同一个路径缓存多条]
*/ 
// cacheAgain.setAgainAgent('/index', {page: 1}, {data:{code: 0}}, 'arr')
// cacheAgain.getAgainAgent('/index', {page: 1}, 'arr')
// if (cacheAgain.resPromise) {
//   return cacheAgain.resPromise
// } else {
//   return axois.get()
// }

export default class againCache {
  constructor () {
    this.author = 'Hansin'
    this.cacheList = []
  }

  getCache (path, preload) {
    if (typeof preload === 'object') {
      preload = JSON.stringify(preload)
    }
    let list = [],res
    this.cacheList.forEach((item) => {
      if (item.path === path) {
        list = item.cache
      }
    })
    list.forEach((n) => {
      if (n.pre === preload && n.res) {
        res = JSON.parse(n.res)
      }
    })
    return res
  }

  setCache (path, preload, res) {
    let havePath = false
    if (typeof preload === 'object') {
      preload = JSON.stringify(preload)
    }
    this.cacheList.forEach((item, i) => {
      if (item.path === path) {
        havePath = true
        let haveRes = false
        item.cache.forEach((li, j) => {
          if (li.pre === preload) {
            haveRes = true
            this.cacheList[i].cache[j].res = JSON.stringify(res)
          }
        })
        if (!haveRes) {
          this.cacheList[i].cache.push({
            pre: preload,
            res: JSON.stringify(res)
          })
        }
      }
    })
    if (!havePath) {
      this.cacheList.push({
        path: path,
        cache: [{
          pre: preload,
          res: JSON.stringify(res)
        }]
      })
    }
  }
}
