Open graup opened 5 years ago
Addition: it works if I leave out the "config": "airbnb"
option from the @vue/cli-plugin-eslint
config, because in that case it doesn't run the lint automatically on completion.
Maybe my suggestion would be to remove the auto-lint here or provide an option to turn if off.
The autolint is needed, we can't drop it. Without it, the whole project would be one big lint error as the files that were generated don't match the rules enforced by the respective standard
/airbnb
/prettier
rules.
However I agree that it would be better to postpone this until all plugin's onComplete
hooks have run.
As an immediate solution to your problem, you can manipulate files before that hook by using api.generator.files
. That property references an object containing all of the project's files as strings, before they are written to disk.
The format is
{
'path-relative-to-project-root': 'file content as string'
}
Yes, that makes sense. Thanks.
I found another workaround. Using this code to push my hook to the front of the callbacks. Not very pretty since it's using private API, but works as well.
api.onCreateCompleteFirst = function(cb) {
this.generator.completeCbs.unshift(cb);
};
api.onCreateCompleteFirst(() => {
....
});
I would strongly advise against using private APIs if possible.
Version
3.6.3
Environment info
Steps to reproduce
Following the preset guide, I'm trying to inject a dependency to the entry file using
api.injectImports
and then add aVue.use()
line for it duringapi.onCreateComplete
. I also added@vue/cli-plugin-eslint
through the preset. The problem is that the eslint plugin's onCreateComplete hook runs before my own, causing a "no-unused-vars" error and failing the create process before I got a chance to add the Vue.use line.preset.json
generator.json
What is expected?
The import is injected, the line of code is added, and everything lints properly.
What is actually happening?
The lint runs before adding the line of code causing a "no-unused-vars" error.
injectImports
adds lines during the initial generation, butonCreateComplete
runs after everything is done, possibly after other plugins.