vscode配置文件之.eslintrc.json

.eslintrc.json

{
  "env": {
    "browser": true,
    "es6": true
  },
  "extends": [
    "plugin:react/recommended",
    "plugin:react-hooks/recommended",
    "plugin:prettier/recommended"
  ],
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "project": "./tsconfig.json"
  },
  "plugins": ["@typescript-eslint", "formatjs", "prettier"],
  "settings": {
    "react": {
      "version": "detect"
    }
  },
  "rules": {
    "@typescript-eslint/no-unused-vars": "error",
    "import/prefer-default-export": "off",
    "react/prop-types": "off",
    "react/jsx-uses-react": "off",
    "react/react-in-jsx-scope": "off",
    "@typescript-eslint/no-non-null-assertion": "off",
    "@typescript-eslint/no-require-imports": "warn",
    "@typescript-eslint/no-this-alias": "error",
    "@typescript-eslint/no-unnecessary-boolean-literal-compare": "off",
    "@typescript-eslint/no-unnecessary-qualifier": "error",
    "@typescript-eslint/no-unused-expressions": "error",
    "@typescript-eslint/no-var-requires": "error",
    "@typescript-eslint/prefer-for-of": "error",
    "@typescript-eslint/prefer-function-type": "error",
    "@typescript-eslint/prefer-namespace-keyword": "error",
    "@typescript-eslint/prefer-readonly": "error",
    "@typescript-eslint/promise-function-async": "warn",
    "@typescript-eslint/quotes": "off",
    "@typescript-eslint/restrict-plus-operands": "warn",
    "react/display-name": "off",
    "no-redeclare": "off",
    "id-blacklist": [
      "error",
      "any",
      "String",
      "string",
      "Boolean",
      "boolean",
      "Undefined",
      "undefined"
    ],
    "one-var": ["error", "never"],
    "prefer-const": "error",
    "prefer-object-spread": "error",
    "prefer-template": "error",
    "quote-props": "off",
    "radix": "off",
    "react/jsx-boolean-value": "error",
    "react/jsx-key": "error",
    "prettier/prettier": [
      "error",
      {
        "endOfLine": "auto"
      }
    ]
  }
}

.eslintignore

node_modules
.DS_Store
dist
dist-ssr
*.local
vite.config.ts
tsconfig.json
src/**/*.d.ts
scripts
mocks

.prettierignore

*.styl
.*ignore
.npmrc
.umi/
.DS_Store
CODEOWNERS
*.ejs
src/assets
!.*.js
dist/
nginx.conf
Dockerfile
Jenkinsfile
*.png
*.xml
*.styl.d.ts
/.docz

.gitignore

node_modules
.DS_Store
dist
dist-ssr
*.local
yarn-error.log
.vscode

tsconfig.json

{
  "compilerOptions": {
    "target": "ESNext",
    "lib": ["DOM", "DOM.Iterable", "ESNext"],
    "types": ["vite/client"],
    "allowJs": false,
    "skipLibCheck": true,
    "esModuleInterop": false,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "baseUrl": "./src",
    "forceConsistentCasingInFileNames": true,
    "module": "ESNext",
    "sourceMap": true,
    "moduleResolution": "Node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react"
  },
  "include": ["./src"],
  "exclude": ["node_modules"]
}

vite.config.ts

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import path from 'path'
import fs from 'fs'
import getThemeVariables from '@ant-design/aliyun-theme/'
import { viteMockServe } from 'vite-plugin-mock'

const paths = fs.readdirSync(path.resolve(__dirname, 'src'))
const alias = paths
  .filter((p) => {
    const stat = fs.statSync(path.resolve(__dirname, 'src/', p))
    return stat.isDirectory()
  })
  .map((p) => ({
    find: p,
    replacement: path.resolve(__dirname, 'src/', p),
  }))

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    react({
      jsxRuntime: 'classic',
      babel: {
        plugins: [
          ['@emotion'],
          [
            'formatjs',
            {
              idInterpolationPattern: '[sha512:contenthash:base64:6]', // formatjs id规则
              removeDefaultMessage: true,
            },
          ],
        ],
      },
    }),
    viteMockServe({
      // default
      mockPath: './mocks',
      localEnabled: !!process.env.VITE_APP_MOCK,
    }),
  ],
  resolve: {
    alias: [...alias, { find: /^~/, replacement: '' }],
  },
  css: {
    preprocessorOptions: {
      less: {
        modifyVars: getThemeVariables,
        javascriptEnabled: true,
      },
    },
  },
  esbuild: {},
  server: {
    hmr: {
      protocol: 'ws',
      host: 'localhost',
      port: 3001,
    },
    port: 3001,
    proxy: process.env.VITE_APP_MOCK
      ? null
      : {
          '/api/': {
            target: '项目IP:端口号 或者网址',
            secure: false,
            changeOrigin: true,
            rewrite: (path) => path.replace(/^\/api/, ''),
          },
        },
  },
})

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值