Vue Typescript Prettier screenshot

Vue Typescript Prettier

Author Avatar Theme by Danielwaltz
Updated: 22 Oct 2021
22 Stars

Vue project with TypeScript, ESLint, and Prettier integrated together

Overview

This article discusses the integration of Vue, TypeScript, ESLint, and Prettier in a Vue project. It highlights the benefits of using these tools together and provides an example using Vue 2.

Features

  • Vue: A progressive JavaScript framework for building user interfaces.
  • TypeScript: A typed superset of JavaScript that compiles to plain JavaScript.
  • ESLint: A pluggable linting utility for JavaScript and TypeScript that helps identify and fix problems in your code.
  • Prettier: An opinionated code formatter that enforces consistent code style.

Installation

Here is a step-by-step guide on installing the above-mentioned tools in your Vue project:

  1. Install Vue using the following command:
npm install vue
  1. Install TypeScript:
npm install typescript
  1. Install ESLint and the necessary plugins:
npm install eslint eslint-plugin-vue @typescript-eslint/parser @typescript-eslint/eslint-plugin
  1. Create an ESLint configuration file .eslintrc.js in the root of your project:
module.exports = {
  root: true,
  env: {
    node: true,
  },
  extends: [
    'plugin:vue/essential',
    '@vue/typescript',
    'prettier',
    'prettier/@typescript-eslint',
  ],
  parserOptions: {
    parser: '@typescript-eslint/parser',
  },
  rules: {},
};
  1. Install Prettier:
npm install prettier
  1. Create a Prettier configuration file .prettierrc in the root of your project to define your preferred code style:
{
  "semi": false,
  "singleQuote": true,
  "trailingComma": "all",
  "arrowParens": "always"
}
  1. Add the following scripts in your package.json file:
"scripts": {
  "lint": "eslint . --ext .ts,.tsx,.vue",
  "lint:fix": "npm run lint -- --fix",
  "format": "prettier --write 'src/**/*.{ts,tsx,vue}'"
}
  1. That’s it! You can now start using Vue, TypeScript, ESLint, and Prettier in your Vue project.

Summary

Integrating Vue, TypeScript, ESLint, and Prettier in a Vue project brings a range of benefits including enhanced code quality, improved debugging experience, and better collaboration among developers. This article provides a comprehensive guide on installing and configuring these tools, allowing you to leverage their combined power in your Vue projects.