Trade‑off: vite-plugin-eslint with eslint-plugin-jsx-a11y vs vite-plugin-a11y for dev‑time accessibility checks
0 reputation · 11 Feb 2021, 03:38 UTC
0 reputation · 11 Feb 2021, 03:38 UTC
Goal: Catch accessibility violations early during Vite dev server execution while keeping hot‑module replacement fast and avoiding extra configuration overhead.
Constraint: Using vite-plugin-eslint with eslint-plugin-jsx-a11y provides terminal and editor feedback but requires an ESLint setup and adds build‑time processing; vite-plugin-a11y runs axe‑core on each HMR update for instant DOM‑level reports without ESLint, yet it may miss JSX‑specific rules and can slow hot reload on larger applications.
Uncertainty: For a medium‑size React SPA, which approach gives the best trade‑off between immediate feedback, configurability, and HMR performance?
35275 reputation · 11 Feb 2021, 14:06 UTC
alt on <img>, incorrect role assignments, or improper button/anchor semantics that eslint‑plugin‑jsx‑a11y flags during static analysis.eslint‑plugin‑jsx‑a11y. vite‑plugin‑eslint adds a one‑time ESLint configuration (typically .eslintrc.js or a flat config) and the need to install the eslint‑plugin‑jsx‑a11y package. Once in place, it offers continuous feedback in the editor, terminal, and Vite dev server, which is valuable for long‑term code quality.ESLint with eslint‑plugin‑jsx‑a11y performs static analysis on the JSX source. It is fast, cacheable, and can be integrated into the editor, but it cannot see what actually renders after React’s reconciliation. vite‑plugin‑a11y runs axe‑core against the rendered DOM on every HMR update, delivering real‑time, runtime‑level feedback. The cost is extra JavaScript execution and DOM traversal, which becomes noticeable as the application grows.
vite‑plugin‑eslint + eslint‑plugin‑jsx‑a11y. Install the ESLint packages, create a minimal .eslintrc.js that extends plugin:jsx-a11y/recommended, and add the plugin to Vite’s plugins array.
import eslint from 'vite-plugin-eslint';
export default {
plugins: [
eslint({
cache: true,
include: ['src/**/*.tsx'],
emitWarning: true
})
]
};
vite‑plugin‑a11y for runtime checks. If you need to surface accessibility issues that only appear after state changes (e.g., dynamic aria‑hidden), add the plugin with a narrow include path or debounce options:
import a11y from 'vite-plugin-a11y';
export default {
plugins: [
a11y({
include: ['src/**/Page*.tsx'],
debounce: 300
})
]
};
alt on an <img> and a div role="button" without keyboard handlers. Confirm that eslint‑plugin‑jsx‑a11y reports the errors immediately, while vite‑plugin‑a11y only reports the role issue if the element is mounted.
Could you confirm whether your project uses the ESLint flat config format (eslint.config.js) or the legacy .eslintrc JSON/YAML? The plugin’s integration and caching behavior differ between the two, which may influence latency measurements.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.