Description
What problem does this feature solve?
Linting is a development-time task. The output of warnings are useful to devs at a time when they can be inspected, addressed or logged elsewhere to be addressed.
Developers run vue-cli-service lint
explicitly? obviously the exact right time to run the linter.
Developers running local development server? also a great time to lint! The lint-warnings overlay is fantastic.
However, running the linter during vue-cli-service build
? Not good. The documentation implies that only lint errors fail the build. However, this isn't strictly true when using additional eslint plugins and configs (like prettier). So the end result is that linting during a production build can prevent the build entirely.
lintOnSave
to the rescue!? Not so fast. Firstly, the configuration setting is misnamed. It does not control whether linting occurs on save but whether linting occurs during a build. There are a plethora of issues and comments regarding lint errors/warnings during build that indicate the lintOnSave
option is not well known nor understood. Indeed, it took days for me to track down why linting was running during our build at all; and even longer before I discovered this option. Had the option been named lintOnBuild
, a quick scan of the docs would have uncovered this behavior much quicker.
But back to the point: why is lintOnSave insufficient? The common recommendation is to have lintOnSave be based on NODE_ENV !== production
. This seems reasonable except npm's own prepare
script (which exists specifically to be hook for running builds/compilation) is not run under "production". So the very environment variable that would be used to disable linting during the build; is precisely what prevents the build from even occurring in the first place. What's more, vue-cli-service build
defaults to running a "production" build, so in that same spirit, it should also disable the linting process.
What does the proposed API look like?
My proposal is that lintOnSave
should be driving by vue's "mode" (not NODE_ENV). In which case:
vue-cli-service serve
would continue to run the linter as its default mode is developmentvue-cli-service build
would not run the linter as its default mode is production.