Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can vite hot update be supported? #394

Open
CaoMeiYouRen opened this issue Dec 5, 2021 · 0 comments
Open

Can vite hot update be supported? #394

CaoMeiYouRen opened this issue Dec 5, 2021 · 0 comments

Comments

@CaoMeiYouRen
Copy link

For example

// src/module/index.ts 
function registerDynamicModule<S>(dynamicModule: Mod<S, any>, modOpt: DynamicModuleOptions) {
  if (!modOpt.name) {
    throw new Error('Name of module not provided in decorator options')
  }

  if (!modOpt.store) {
    throw new Error('Store not provided in decorator options when using dynamic option')
  }
////
  if (import.meta.hot) {
    // Hot update of vite. 
    if (modOpt.store.hasModule(modOpt.name)) {
      // Hot update if duplicate modules are encountered. 
      modOpt.store.hotUpdate({
        modules: {
          [modOpt.name]: dynamicModule
        }
      })
      return
    }
  }
////
  modOpt.store.registerModule(modOpt.name, dynamicModule, {
    preserveState: modOpt.preserveState || false
  })
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant