FRONTEND BEST PRACTICES

Frontend best practices

Code Quality and Standards

  1. ESLint
    ESLint Nuxt Configuration
    A linting tool for identifying and fixing issues in JavaScript and Vue codebases.
  2. Prettier
    Why Prettier?
    Prettier enforces a consistent code format to improve readability across the codebase.
  3. Unit Testing
    Unit testing verifies the functionality of individual components, ensuring that each works as expected.
    • Vue Testing Library Provides a testing approach that emphasizes component behavior, making tests more maintainable.
    • Vitest A fast, easy-to-configure unit testing framework for Vue 3, compatible with Vite.
  4. TypeScript
    TypeScript Handbook
    TypeScript adds static typing to JavaScript, making codebases more predictable and easier to refactor.
  5. Visual Regression Testing
    Visual regression testing tools like Chromatic and Percy help catch unintended changes in component design or layout.
  6. Code Review
    Regular code reviews ensure code quality, consistency, and adherence to best practices.
  7. Documentation
    Documenting code, components, and design systems helps onboard new team members and maintain codebases effectively.
  8. Automation and CI/CD
    Automate linting, testing, and deployment processes to ensure code quality and consistency.

Scoped Styles

Scoped styles provide a way to apply CSS specifically to individual components, avoiding global style conflicts and making CSS more manageable in large applications. Here are some resources to learn more:

Atomic CSS

Atomic CSS is a utility-first approach to styling where classes are highly reusable, concise, and meant to serve specific purposes, like layout and color. This approach minimizes CSS bloat and improves the speed of development.

  • Introduction to Atomic CSS
    CSS-Tricks - Atomic CSS
    Provides an overview of Atomic CSS principles and explains how it can streamline styling workflows.

  • Why Atomic CSS
    Figma - Design Systems Benefits of Atomic CSS
    Resource on how Atomic CSS supports consistent, maintainable UI designs in a component-driven structure.

  • Tailwind CSS (a popular atomic CSS framework)
    Tailwind CSS Documentation
    Shows how a utility-first approach with Atomic CSS promotes reusability, customization, and faster development cycles.

  • Atomic Web Design
    Atomic Web Design
    Brad Frost’s blog on atomic web design, which promotes creating reusable and scalable UI components.

Storybook

Storybook is a powerful tool for developing, testing, and documenting UI components in isolation, making it a favourite for component-driven development.

  • Storybook Official Documentation
    Storybook Documentation
    Comprehensive guides on Storybook, from getting started to advanced usage, emphasizing component-driven development.

  • Visual Regression Testing (VRT)
    Tools for VRT allow you to track visual changes in your components, ensuring UI consistency.

    • Chromatic
      Chromatic
      Automates visual testing for Storybook components.

    • Percy
      Percy
      Enables snapshot-based visual testing to catch visual regressions in your UI.

  • Storybook and Component Libraries Why You Should Use Storybook Discusses how Storybook enhances developer experience, team collaboration, and UI consistency by building UI components in isolation.

  • Distribute UI across an organization Discusses a walk through of design system distribution from packaging UI components to importing them into other apps.

TypeScript

TypeScript adds static typing to JavaScript, making codebases more predictable, easier to refactor, and enabling better tooling support.

Learning

You can test TS features in the TS Playground

Also a good resource is https://www.totaltypescript.com/ they have some free workshops on https://github.com/total-typescript which are really good.

TypeScript packages

  • tsx TypeScript Execute (tsx): The easiest way to run TypeScript in Node.js
  • vue-tsc Provides type-checking capabilities specifically for Vue components in TypeScript, without needing to compile. Useful for CI pipelines and pre-build type-checking.

Summary

With these resources, you can build a solid foundation for component-driven development and write maintainable, scalable, and efficient code.