GithubHelp home page GithubHelp logo

hottredpen / typescript-vue-eslint-starter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vok123/typescript-vue-eslint-starter

0.0 1.0 0.0 126 KB

typescript + babel + vue + eslint + webpack4. Support tsx

License: MIT License

JavaScript 44.32% Vue 34.29% HTML 2.97% TypeScript 18.42%

typescript-vue-eslint-starter's Introduction

TypeScript-Babel-Vue-Eslint-Starter


Webpack 4.0+
Typescript 3.7+
Eslint 7.0+
Vue 2.0+
Babel 7.0+

babel + typescript faster than only typescript, support tsx

Start

npm install
npm run dev
npm run build

Usage

1. Install

  • Install devDependencies
npm i -D
  @typescript-eslint/eslint-plugin
  @typescript-eslint/parser
  eslint
  eslint-config-standard
  eslint-plugin-standard
  eslint-plugin-import
  eslint-plugin-promise
  eslint-webpack-plugin
  eslint-plugin-node
  eslint-plugin-vue
  typescript
  @babel/cli
  @babel/core
  @babel/plugin-proposal-class-properties
  @babel/plugin-proposal-decorators
  @babel/plugin-proposal-numeric-separator
  @babel/plugin-proposal-object-rest-spread
  @babel/preset-env
  @babel/preset-typescript
  babel-eslint
  babel-loader
  • Install dependencies
npm i -S vue-class-component vue-property-decorator

2. Webpack config (add babel-loader)

const ESLintPlugin = require('eslint-webpack-plugin');

{
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          compilerOptions: {
            preserveWhitespace: false
          }
        }
      },
      {
        test: /\.ts(x)?$/,
        exclude: /node_modules/,
        use: [
          'babel-loader'
        ]
      }
    ];
  },
  plugins: [
    new ESLintPlugin({
      fix: false,
      extensions: ['.js', '.jsx', '.vue', '.ts', '.tsx'],
      cache: false,
      emitWarning: true,
      emitError: true
    })
  ]
}

3. Add .eslintrc.js

module.exports = {
  plugins: ['vue', '@typescript-eslint'],
  parserOptions: {
    parser: '@typescript-eslint/parser',
    env: { es6: true },
    sourceType: 'module'
  },
  root: true,
  env: {
    browser: true,
    node: true
  },
  extends: ['plugin:vue/base', 'plugin:@typescript-eslint/recommended', 'plugin:vue/essential', 'standard'],
  rules: {
    // default eslint rules
    'one-var': 0,
    'arrow-parens': 0,
    'generator-star-spacing': 0,
    'no-debugger': 0,
    'no-console': 0,
    semi: [2, 'always'],
    'no-extra-semi': 2,
    'space-before-function-paren': 0,
    eqeqeq: 0,
    'spaced-comment': 0,
    'no-useless-escape': 0,
    'no-tabs': 0,
    'no-mixed-spaces-and-tabs': 0,
    'new-cap': 0,
    camelcase: 0,
    'no-new': 0,
    indent: 'off',
    semi: 'off',
    // typescript-eslint rules
    // https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin/docs/rules
    '@typescript-eslint/semi': ['error'],
    '@typescript-eslint/indent': ['error', 2],
    '@typescript-eslint/explicit-function-return-type': 0
  }
};

4. Add tsconfig.json

{
  "compilerOptions": {
    "target": "es6",
    "module": "ESNext",
    "strict": true,
    "jsx": "preserve",
    "importHelpers": true,
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "allowJs": true,
    "baseUrl": ".",
    "types": ["webpack-env", "node"],
    "paths": {
      "@/*": ["src/*"]
    },
    "lib": ["ESNext", "dom", "dom.iterable", "scripthost"]
  },
  "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue", "tests/**/*.ts", "tests/**/*.tsx"],
  "exclude": ["node_modules"]
}

5. Add .babelrc

{
  "presets": ["@babel/env", "@babel/typescript", "@vue/babel-preset-jsx"],
  "plugins": [
    "@babel/proposal-numeric-separator",
    [
      "@babel/proposal-decorators",
      {
        "legacy": true
      }
    ],
    ["@babel/proposal-class-properties", { "loose": false }],
    "@babel/proposal-object-rest-spread"
  ]
}

typescript-vue-eslint-starter's People

Contributors

dependabot[bot] avatar vok123 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.