core icon indicating copy to clipboard operation
core copied to clipboard

feat(core): add hook before initialize

Open EdieLemoine opened this issue 3 years ago • 1 comments

This adds a lifecycle hook before the app is initialized. I'm not sure if you want this implemented,

I want to change/update locale data through a plugin, but I noticed the changes are not being reflected in the pages array in other plugins. I checked out the source and discovered this is because the earliest hook, onInitialized happens after pages are resolved. So I added another hook right before it.

I've updated the unit tests and tested it with my use case and it works like a charm.

EdieLemoine avatar Aug 16 '22 09:08 EdieLemoine

I'm not sure if it is necessary because we can do things in plugin before initialization via "PluginFunction":

const fooPlugin = (app) => {
  // here we can do things just like beforeInitialize

  return {
    name: 'vuepress-plugin-foo',
    onInitialized(app) {  /* ... */ }
  }
}

meteorlxy avatar Aug 17 '22 02:08 meteorlxy

@meteorlxy Wow, I blame tunnel vision. If having this as a hook doesn't have any other advantages this can be closed. :) Thanks

EdieLemoine avatar Aug 18 '22 10:08 EdieLemoine