vue-keep-alive-dev

A plugin to resolve HMR issues with the core keep-alive plugin
2,926 4
Install
npm install vue-keep-alive-dev
Latest Version:1.0.2
Vue:2
License:MIT
Last Updated:Jan 6, 2023
Links: GitHub  ·  npm
Maintainer: dwatts3624

VueKeepAliveDev

This plugin resolves an issue where webpack's Hot Module Replacement (MHR) doesn't work for keep-alive components (e.g. router-view, etc).

I was struggling to deal with the suggested workarounds that just disable keep-alive in development with exclude patterns or a dynamic component. I quickly noticed that this creates a completely different hook flow where the created/activated/deactived/destroyed hooks would have be tuned based on local vs production and it was getting ugly! Hoping this solution helps others avoid having to create confusing patterns between dev & production.

Credit

Full credit to nailfar & ericwu-wish in https://github.com/vuejs/vue-loader/issues/1332 for this entire solution. I just packaged it up to make this easier.

Installation

1. Install

yarn add vue-keep-alive-dev
# or
npm i vue-keep-alive-dev --save

2. Activate

import VueKeepAliveDev from 'vue-keep-alive-dev'

Vue.use(VueKeepAliveDev, {
  environment: 'development' // Your environment when HMR is in use
});

3. Run

In your package.json ensure that the NODE_ENV lines up with whatever you're setting when compiling Vue.

Example:

{
  "scripts": {
    "dev": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --progress --inline --hot --config=webpack.config.js"
  }
}

Configuration

  • environment - The NODE_ENV when HMR is in use. Defaults to development.

License

MIT

Related Packages

keep-alive-vue3

Extend vue3 keep-alive and router-view, add the function of automatically judgin...

868 3
vue3-keep-alive-component

A workaround solution for vue3 router&keep-alive components issue: keep-alive co...

7,358 17
@xsbcme/vue-tab-router

Vue 3 多标签页路由插件,适用于后台管理系统、工作台和多文档编辑场景。

5,258 12

Version History

Version Released Vue License
1.0.2 ^2.6.10 MIT
1.0.1 ^2.6.10 MIT
1.0.0 ^2.6.10 MIT
0.0.1 ^2.6.10 MIT