-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Hook to act after others plugins invocation #1754
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
Comments
We can also use hook mechanism for events. For example, apollo plugin has a postprocess where it's checks for typescripts and converts accordingly. Ideally this should be done by other 3rd party plugins too, but isn't it better that only typescript defines this and other plugins doesn't need to care about it? So, the typescript plugin defines something like this, api.hook('afterGenerate', (files) => {
convertFiles(files)
}); |
Here's my proposal. @yyx990803 @LinusBorg @Akryum Would appreciate thoughts. Callback/Hook API ProposalThere are a lot of different reasons for having a plugin system. But one of the main reasons is to provide flexibility. A good system should allow plugins to interact with each other but still be independent of each other. All related code for certain feature should be contained to a certain plugin rather than relying on other plugins. Given below is the proposal of the API Type of CallbacksafterRender (postProcessFiles)It behaves like how the current ExampleA plugin which generates modules would want to insert those modules into certain parts of existing code. This hook can be used to do that after the module is created. afterAnyRenderThe function provided to this will be executed after template rendering is done and we get an JS object containing the files. It will be executed for all the plugins installed in the project. ExampleTypescript plugin would want to convert all the files irrespective of which plugin they were generated from before writing them to the disk. afterWrite (onCreateComplete)It behaves like how the current ExampleSimilar example to afterAnyWriteThe function provided to this will be executed after writing the generated files to the disk and installing the injected dependencies. It will be executed for all the plugins installed in the project. ExampleEslint plugin would want to beforeAnyRenderThe function provided to this will be executed before the files are resolved in vue-cli. It will be executed for all the plugins installed in the project. ExampleTypescript plugin (or other conversion plugins) would want to convert the files from local disk to JS first, then let the other plugins manipulate them without caring what kind of format the files are in. And then after the files are rendered, the plugins can convert them back with DrawbacksWhenever a plugin is invoked, all the other plugins which were installed would be loaded to be checked if they have any callbacks. This might increase the running time of Why in 3.0.0?Once we release 3.0.0, there will be a lot of 3rd party plugins created by the users, and it will become an issue if they don't take care of how their plugins will interact with other plugins (especially typescript, lint). In order to make sure that it won't become a big mess that we try to unravel with the next major update, we should try to make sure that we do this before releasing v3. |
@yyx990803 Thoughts? |
@yyx990803 Does the label you added means I can work on this and submit PR? |
Implemented in #2337. Please take a look. Will write docs as a separate PR. |
What problem does this feature solve?
(Plugins dev API)
I don't know if this already exists or possible, but I need a method to listen other plugins
invocation inside my plugin, to alter files contents.
Simple use case:
I want to replace default import of PWA plugin (
import './registerServiceWorker'
) to :ATM, I use
api.postProcessFiles()
function, but this one only work if I do:But if I do
my-plugin
is not aware that PWA was added/invoked, so I cant transform the import statement.What does the proposed API look like?
Something like
api.postProcessFiles()
Thanks !
The text was updated successfully, but these errors were encountered: