Skip to content

VSCode配置

pnpm受限解决办法:管理员权限运行power shell

bash
set-ExecutionPolicy RemoteSigned
set-ExecutionPolicy RemoteSigned
json
{
  "editor.formatOnSave": true,
  "editor.tokenColorCustomizations": {
    "comments": "#408653" // 注释
  },
  "workbench.iconTheme": "material-icon-theme",
  "workbench.colorTheme": "One Dark Pro",
  "editor.fontFamily": " Consolas,微软雅黑, 'Courier New', monospace,Inconsolata",
  "editor.fontSize": 16,
  "eslint.format.enable": true,
  "eslint.options": {
    "extensions": [
      ".js",
      ".jsx",
      ".vue",
      ".ts",
      ".tsx"
    ]
  },
  "eslint.validate": [
    "vue",
    "html",
    "javascript",
    "typescript",
    "javascriptreact",
    "typescriptreact"
  ],
  "stylelint.enable": true,
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": "always",
    "source.fixAll.stylelint": "always"
  },
  "stylelint.validate": [
    "css",
    "less",
    "postcss",
    "scss",
    "vue",
    "sass"
  ],
  "[jsonc]": {
    "editor.defaultFormatter": "vscode.json-language-features"
  },
  "GitCommitPlugin.ShowEmoji": false,
  "GitCommitPlugin.MaxSubjectCharacters": 200,
  "eslint.codeActionsOnSave.rules": null,
  "editor.mouseWheelZoom": true,
  "[vue]": {
    "editor.defaultFormatter": "dbaeumer.vscode-eslint"
  },
  "security.workspace.trust.untrustedFiles": "open",
}
{
  "editor.formatOnSave": true,
  "editor.tokenColorCustomizations": {
    "comments": "#408653" // 注释
  },
  "workbench.iconTheme": "material-icon-theme",
  "workbench.colorTheme": "One Dark Pro",
  "editor.fontFamily": " Consolas,微软雅黑, 'Courier New', monospace,Inconsolata",
  "editor.fontSize": 16,
  "eslint.format.enable": true,
  "eslint.options": {
    "extensions": [
      ".js",
      ".jsx",
      ".vue",
      ".ts",
      ".tsx"
    ]
  },
  "eslint.validate": [
    "vue",
    "html",
    "javascript",
    "typescript",
    "javascriptreact",
    "typescriptreact"
  ],
  "stylelint.enable": true,
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": "always",
    "source.fixAll.stylelint": "always"
  },
  "stylelint.validate": [
    "css",
    "less",
    "postcss",
    "scss",
    "vue",
    "sass"
  ],
  "[jsonc]": {
    "editor.defaultFormatter": "vscode.json-language-features"
  },
  "GitCommitPlugin.ShowEmoji": false,
  "GitCommitPlugin.MaxSubjectCharacters": 200,
  "eslint.codeActionsOnSave.rules": null,
  "editor.mouseWheelZoom": true,
  "[vue]": {
    "editor.defaultFormatter": "dbaeumer.vscode-eslint"
  },
  "security.workspace.trust.untrustedFiles": "open",
}

VSCode插件

Chinese (Simplified) (简体中文) Language Pack for Visual Studio Code

ESLint

Git Graph

git-commit-plugin

GitLens — Git supercharged

Live Server

markdownlint

Material Icon Theme

One Dark Pro

Stylelint

TRAE AI

Vue (Official)

Vue VSCode Snippets

Vite配置

多环境配置

vite使用dotenv来从项目目录下读取相应的配置文件,从而获取额外的环境变量。

举例:

bash
.env        # 所有情况下都会加载
.env.sit    # 只在 --mode sit的时候加载,对应测试环境的配置
.env.prod   # 只在 --mode prod的时候加载,对应生产环境的配置
.env        # 所有情况下都会加载
.env.sit    # 只在 --mode sit的时候加载,对应测试环境的配置
.env.prod   # 只在 --mode prod的时候加载,对应生产环境的配置

在不同文件下写相对应的环境变量配置

bash
# .env.sit
# 静态资源部署路径
VITE_PUBLIC_PATH = /
# 测试环境使用vConsole
VITE_USE_VCONSOLE = true
# 测试环境域名
VITE_API_DOMAIN = https://yoururl.test.com
# 测试环境api前缀
VITE_API_PREFIX = /testApi
# .env.sit
# 静态资源部署路径
VITE_PUBLIC_PATH = /
# 测试环境使用vConsole
VITE_USE_VCONSOLE = true
# 测试环境域名
VITE_API_DOMAIN = https://yoururl.test.com
# 测试环境api前缀
VITE_API_PREFIX = /testApi
bash
# .env.prod
# 静态资源部署路径
VITE_PUBLIC_PATH = /vueApp
# 生产环境不使用vConsole
VITE_USE_VCONSOLE = false
# 生产环境域名
VITE_API_DOMAIN = https://yoururl.com
# 生产环境api前缀
VITE_API_PREFIX = /api
# .env.prod
# 静态资源部署路径
VITE_PUBLIC_PATH = /vueApp
# 生产环境不使用vConsole
VITE_USE_VCONSOLE = false
# 生产环境域名
VITE_API_DOMAIN = https://yoururl.com
# 生产环境api前缀
VITE_API_PREFIX = /api

只有VITE_开头的变量才会暴露给经过vite构建处理的代码

vite.config.js中进行差异化配置

jsx
import { defineConfig, loadEnv } from 'vite'
export default defineConfig(({ mode }) => {
    // 项目根路径
    const root = process.cwd()
    // 通过vite提供的工具方法去加载相应环境的配置
    // 这里的mode就是自定义的环境 --mode prod的prod
    const { VITE_PUBLIC_PATH } = loadEnv(mode, root)
    return {
        // 这里根据环境不同,设置不同的静态资源部署路径
        base: VITE_PUBLIC_PATH,
    }
})
import { defineConfig, loadEnv } from 'vite'
export default defineConfig(({ mode }) => {
    // 项目根路径
    const root = process.cwd()
    // 通过vite提供的工具方法去加载相应环境的配置
    // 这里的mode就是自定义的环境 --mode prod的prod
    const { VITE_PUBLIC_PATH } = loadEnv(mode, root)
    return {
        // 这里根据环境不同,设置不同的静态资源部署路径
        base: VITE_PUBLIC_PATH,
    }
})

在api请求中做差异化配置

jsx
const apiUrl = ref(`${import.meta.env.VITE_API_DOMAIN}`);
if (import.meta.env.VITE_XXX) {
    // 做差异化处理
}
const apiUrl = ref(`${import.meta.env.VITE_API_DOMAIN}`);
if (import.meta.env.VITE_XXX) {
    // 做差异化处理
}

支持jsx

安装插件@vitejs/plugin-vue-jsx

bash
pnpm i @vitejs/plugin-vue-jsx
pnpm i @vitejs/plugin-vue-jsx
jsx
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'

export default defineConfig(({ mode }) => {
    const root = process.cwd()
    const { VITE_PUBLIC_PATH } = loadEnv(mode, root)
    return {
        base: VITE_PUBLIC_PATH,
        // 增加jsx插件来支持jsx的写法
        plugins: [vue(), vueJsx()]
    }
})
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'

export default defineConfig(({ mode }) => {
    const root = process.cwd()
    const { VITE_PUBLIC_PATH } = loadEnv(mode, root)
    return {
        base: VITE_PUBLIC_PATH,
        // 增加jsx插件来支持jsx的写法
        plugins: [vue(), vueJsx()]
    }
})

路径别名

通过alias配置路径别名

js
return {
    resolve: {
        alias: [
            // import xxx from '@/path' -> import xxx from 'src/path'
            {
                find: /@/,
                replacement: resolvePath('src'),
            },
        ],
    },
}
return {
    resolve: {
        alias: [
            // import xxx from '@/path' -> import xxx from 'src/path'
            {
                find: /@/,
                replacement: resolvePath('src'),
            },
        ],
    },
}

构建选项

js
{
    // ...
    build: {
        // 我们的构建产物需要兼容到es6
        target: 'es2015',
        // 假如要兼容安卓微信的webview
        cssTarget: 'chrome61',
        // 非生产环境下生成sourcemap
        sourcemap: mode !== 'prod',
        // 禁用gzip 压缩大小报告,因为压缩大型文件可能会很慢
        reportCompressedSize: false,
        // chunk大小超过1500kb是触发警告
        chunkSizeWarningLimit: 1500,
        terserOptions: {
            compress: {
            //生产环境时移除console
            drop_console: true,
            drop_debugger: true,
            },
        }
    },
}
{
    // ...
    build: {
        // 我们的构建产物需要兼容到es6
        target: 'es2015',
        // 假如要兼容安卓微信的webview
        cssTarget: 'chrome61',
        // 非生产环境下生成sourcemap
        sourcemap: mode !== 'prod',
        // 禁用gzip 压缩大小报告,因为压缩大型文件可能会很慢
        reportCompressedSize: false,
        // chunk大小超过1500kb是触发警告
        chunkSizeWarningLimit: 1500,
        terserOptions: {
            compress: {
            //生产环境时移除console
            drop_console: true,
            drop_debugger: true,
            },
        }
    },
}

服务器配置

js
server: {
    // 开启https
    https: true,
    // 监听所有ip地址
    host: true,
    // 端口默认是5173
    port: 6666,
    // 配置代理帮我们转发请求,解决跨域问题
    proxy: {
        // api/开头的请求将被转发到下面的target的地址
        'api/': {
            target: 'https://mock.com',
            // 改变请求头的origin
            changeOrigin: true,
            // 支持代理websocket
            ws: true,
            // 路径重写 相当于把api/去掉
            rewrite: (path) => path.replace(new RegExp(`^api/`), ''),
        }
    },
},
server: {
    // 开启https
    https: true,
    // 监听所有ip地址
    host: true,
    // 端口默认是5173
    port: 6666,
    // 配置代理帮我们转发请求,解决跨域问题
    proxy: {
        // api/开头的请求将被转发到下面的target的地址
        'api/': {
            target: 'https://mock.com',
            // 改变请求头的origin
            changeOrigin: true,
            // 支持代理websocket
            ws: true,
            // 路径重写 相当于把api/去掉
            rewrite: (path) => path.replace(new RegExp(`^api/`), ''),
        }
    },
},

js.config

json
{
    "compilerOptions": {
        "target": "es2015",  // 指定要使用的默认库,值为"es3","es5","es2015"...
        "module": "commonjs", // 在生成模块代码时指定模块系统
        "checkJs": false, // 启用javascript文件的类型检查
        "baseUrl": "*", // 解析非相关模块名称的基础目录
        "paths": {
            "utils": ["src/utils/*"] // 指定相对于baseUrl选项计算的路径映射,使用webpack别名,智能感知路径
        }
    },
    "exclude": [ // 要排除的文件
        "node_modules",
        "**/node_modules/*"
    ],
    "include": [ // 包含的文件
        "src/*.js"
    ],
    "compilerOptions": {
        "incremental": true, // TS编译器在第一次编译之后会生成一个存储编译信息的文件,第二次编译会在第一次的基础上进行增量编译,可以提高编译的速度
        "tsBuildInfoFile": "./buildFile", // 增量编译文件的存储位置
        "diagnostics": true, // 打印诊断信息
        "target": "ES5", // 目标语言的版本
        "module": "CommonJS", // 生成代码的模板标准
        "outFile": "./app.js", // 将多个相互依赖的文件生成一个文件,可以用在AMD模块中,即开启时应设置"module": "AMD",
        "lib": ["DOM", "ES2015", "ScriptHost", "ES2019.Array"], // TS需要引用的库,即声明文件,es5 默认引用dom、es5、scripthost,如需要使用es的高级版本特性,通常都需要配置,如es8的数组新特性需要引入"ES2019.Array",
        "allowJS": true, // 允许编译器编译JS,JSX文件
        "checkJs": true, // 允许在JS文件中报错,通常与allowJS一起使用
        "outDir": "./dist", // 指定输出目录
        "rootDir": "./", // 指定输出文件目录(用于输出),用于控制输出目录结构
        "declaration": true, // 生成声明文件,开启后会自动生成声明文件
        "declarationDir": "./file", // 指定生成声明文件存放目录
        "emitDeclarationOnly": true, // 只生成声明文件,而不会生成js文件
        "sourceMap": true, // 生成目标文件的sourceMap文件
        "inlineSourceMap": true, // 生成目标文件的inline SourceMap,inline SourceMap会包含在生成的js文件中
        "declarationMap": true, // 为声明文件生成sourceMap
        "typeRoots": [], // 声明文件目录,默认时node_modules/@types
        "types": [], // 加载的声明文件包
        "removeComments":true, // 删除注释
        "noEmit": true, // 不输出文件,即编译后不会生成任何js文件
        "noEmitOnError": true, // 发送错误时不输出任何文件
        "noEmitHelpers": true, // 不生成helper函数,减小体积,需要额外安装,常配合importHelpers一起使用
        "importHelpers": true, // 通过tslib引入helper函数,文件必须是模块
        "downlevelIteration": true, // 降级遍历器实现,如果目标源是es3/5,那么遍历器会有降级的实现
        "strict": true, // 开启所有严格的类型检查
        "alwaysStrict": true, // 在代码中注入'use strict'
        "noImplicitAny": true, // 不允许隐式的any类型
        "strictNullChecks": true, // 不允许把null、undefined赋值给其他类型的变量
        "strictFunctionTypes": true, // 不允许函数参数双向协变
        "strictPropertyInitialization": true, // 类的实例属性必须初始化
        "strictBindCallApply": true, // 严格的bind/call/apply检查
        "noImplicitThis": true, // 不允许this有隐式的any类型
        "noUnusedLocals": true, // 检查只声明、未使用的局部变量(只提示不报错)
        "noUnusedParameters": true, // 检查未使用的函数参数(只提示不报错)
        "noFallthroughCasesInSwitch": true, // 防止switch语句贯穿(即如果没有break语句后面不会执行)
        "noImplicitReturns": true, //每个分支都会有返回值
        "esModuleInterop": true, // 允许export=导出,由import from 导入
        "allowUmdGlobalAccess": true, // 允许在模块中全局变量的方式访问umd模块
        "moduleResolution": "node", // 模块解析策略,ts默认用node的解析策略,即相对的方式导入
        "baseUrl": "./", // 解析非相对模块的基地址,默认是当前目录
        "paths": { // 路径映射,相对于baseUrl
            // 如使用jq时不想使用默认版本,而需要手动指定版本,可进行如下配置
            "jquery": ["node_modules/jquery/dist/jquery.min.js"]
        },
        "rootDirs": ["src","out"], // 将多个目录放在一个虚拟目录下,用于运行时,即编译后引入文件的位置可能发生变化,这也设置可以虚拟src和out在同一个目录下,不用再去改变路径也不会报错
        "listEmittedFiles": true, // 打印输出文件
        "listFiles": true// 打印编译的文件(包括引用的声明文件)
    }
}
{
    "compilerOptions": {
        "target": "es2015",  // 指定要使用的默认库,值为"es3","es5","es2015"...
        "module": "commonjs", // 在生成模块代码时指定模块系统
        "checkJs": false, // 启用javascript文件的类型检查
        "baseUrl": "*", // 解析非相关模块名称的基础目录
        "paths": {
            "utils": ["src/utils/*"] // 指定相对于baseUrl选项计算的路径映射,使用webpack别名,智能感知路径
        }
    },
    "exclude": [ // 要排除的文件
        "node_modules",
        "**/node_modules/*"
    ],
    "include": [ // 包含的文件
        "src/*.js"
    ],
    "compilerOptions": {
        "incremental": true, // TS编译器在第一次编译之后会生成一个存储编译信息的文件,第二次编译会在第一次的基础上进行增量编译,可以提高编译的速度
        "tsBuildInfoFile": "./buildFile", // 增量编译文件的存储位置
        "diagnostics": true, // 打印诊断信息
        "target": "ES5", // 目标语言的版本
        "module": "CommonJS", // 生成代码的模板标准
        "outFile": "./app.js", // 将多个相互依赖的文件生成一个文件,可以用在AMD模块中,即开启时应设置"module": "AMD",
        "lib": ["DOM", "ES2015", "ScriptHost", "ES2019.Array"], // TS需要引用的库,即声明文件,es5 默认引用dom、es5、scripthost,如需要使用es的高级版本特性,通常都需要配置,如es8的数组新特性需要引入"ES2019.Array",
        "allowJS": true, // 允许编译器编译JS,JSX文件
        "checkJs": true, // 允许在JS文件中报错,通常与allowJS一起使用
        "outDir": "./dist", // 指定输出目录
        "rootDir": "./", // 指定输出文件目录(用于输出),用于控制输出目录结构
        "declaration": true, // 生成声明文件,开启后会自动生成声明文件
        "declarationDir": "./file", // 指定生成声明文件存放目录
        "emitDeclarationOnly": true, // 只生成声明文件,而不会生成js文件
        "sourceMap": true, // 生成目标文件的sourceMap文件
        "inlineSourceMap": true, // 生成目标文件的inline SourceMap,inline SourceMap会包含在生成的js文件中
        "declarationMap": true, // 为声明文件生成sourceMap
        "typeRoots": [], // 声明文件目录,默认时node_modules/@types
        "types": [], // 加载的声明文件包
        "removeComments":true, // 删除注释
        "noEmit": true, // 不输出文件,即编译后不会生成任何js文件
        "noEmitOnError": true, // 发送错误时不输出任何文件
        "noEmitHelpers": true, // 不生成helper函数,减小体积,需要额外安装,常配合importHelpers一起使用
        "importHelpers": true, // 通过tslib引入helper函数,文件必须是模块
        "downlevelIteration": true, // 降级遍历器实现,如果目标源是es3/5,那么遍历器会有降级的实现
        "strict": true, // 开启所有严格的类型检查
        "alwaysStrict": true, // 在代码中注入'use strict'
        "noImplicitAny": true, // 不允许隐式的any类型
        "strictNullChecks": true, // 不允许把null、undefined赋值给其他类型的变量
        "strictFunctionTypes": true, // 不允许函数参数双向协变
        "strictPropertyInitialization": true, // 类的实例属性必须初始化
        "strictBindCallApply": true, // 严格的bind/call/apply检查
        "noImplicitThis": true, // 不允许this有隐式的any类型
        "noUnusedLocals": true, // 检查只声明、未使用的局部变量(只提示不报错)
        "noUnusedParameters": true, // 检查未使用的函数参数(只提示不报错)
        "noFallthroughCasesInSwitch": true, // 防止switch语句贯穿(即如果没有break语句后面不会执行)
        "noImplicitReturns": true, //每个分支都会有返回值
        "esModuleInterop": true, // 允许export=导出,由import from 导入
        "allowUmdGlobalAccess": true, // 允许在模块中全局变量的方式访问umd模块
        "moduleResolution": "node", // 模块解析策略,ts默认用node的解析策略,即相对的方式导入
        "baseUrl": "./", // 解析非相对模块的基地址,默认是当前目录
        "paths": { // 路径映射,相对于baseUrl
            // 如使用jq时不想使用默认版本,而需要手动指定版本,可进行如下配置
            "jquery": ["node_modules/jquery/dist/jquery.min.js"]
        },
        "rootDirs": ["src","out"], // 将多个目录放在一个虚拟目录下,用于运行时,即编译后引入文件的位置可能发生变化,这也设置可以虚拟src和out在同一个目录下,不用再去改变路径也不会报错
        "listEmittedFiles": true, // 打印输出文件
        "listFiles": true// 打印编译的文件(包括引用的声明文件)
    }
}

微信小程序setting配置

微信开发者工具安装prettiereslint插件

json
{
    "editor.glyphMargin": false,
    "editor.fontFamily": "JetBrains Mono,'Fira Code',微软雅黑",
    "editor.fontSize": 18,
    "editor.lineHeight": 28,
    "files.autoSave": "off",
    "editor.wordWrap": "on",
    "editor.minimap.enabled": false,
    "editor.insertSpaces": false,
    "editor.tabSize": 2,
    "workbench.editor.enablePreview": true,
    "workbench.editor.enablePreviewFromQuickOpen": true,
    "editor.detectIndentation": true,
    "workbench.editorAssociations": [
        {
            "filenamePattern": "project.miniapp.json",
            "viewType": "settingsEditor.settingsedit"
        }
    ],
    "files.eol": "auto",
    "workbench.colorTheme": "One Dark Pro",
    "[javascript]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "[scss]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "[json]": {
        "editor.defaultFormatter": "vscode.json-language-features"
    },
    "editor.defaultFormatter": "esbenp.prettier-vscode",
    "[wxml]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "[wxss]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "prettier.documentSelectors": [
        "**/*.wxml",
        "**/*.wxss"
    ],
    "editor.formatOnSave": true,
    "prettier.printWidth": 120,
    "prettier.tabWidth": 2,
    "prettier.useTabs": false,
    "prettier.bracketSpacing": true,
    "prettier.semi": false,
    "prettier.singleQuote": true,
    "prettier.quoteProps": "as-needed",
    "prettier.trailingComma": "none",
    "editor.mouseWheelZoom": true
}
{
    "editor.glyphMargin": false,
    "editor.fontFamily": "JetBrains Mono,'Fira Code',微软雅黑",
    "editor.fontSize": 18,
    "editor.lineHeight": 28,
    "files.autoSave": "off",
    "editor.wordWrap": "on",
    "editor.minimap.enabled": false,
    "editor.insertSpaces": false,
    "editor.tabSize": 2,
    "workbench.editor.enablePreview": true,
    "workbench.editor.enablePreviewFromQuickOpen": true,
    "editor.detectIndentation": true,
    "workbench.editorAssociations": [
        {
            "filenamePattern": "project.miniapp.json",
            "viewType": "settingsEditor.settingsedit"
        }
    ],
    "files.eol": "auto",
    "workbench.colorTheme": "One Dark Pro",
    "[javascript]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "[scss]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "[json]": {
        "editor.defaultFormatter": "vscode.json-language-features"
    },
    "editor.defaultFormatter": "esbenp.prettier-vscode",
    "[wxml]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "[wxss]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "prettier.documentSelectors": [
        "**/*.wxml",
        "**/*.wxss"
    ],
    "editor.formatOnSave": true,
    "prettier.printWidth": 120,
    "prettier.tabWidth": 2,
    "prettier.useTabs": false,
    "prettier.bracketSpacing": true,
    "prettier.semi": false,
    "prettier.singleQuote": true,
    "prettier.quoteProps": "as-needed",
    "prettier.trailingComma": "none",
    "editor.mouseWheelZoom": true
}

项目根目录

json
{
    "printWidth": 120,
    "tabWidth": 2,
    "useTabs": false,
    "bracketSpacing": true,
    "semi": false,
    "singleQuote": true,
    "quoteProps": "as-needed",
    "trailingComma": "none",
    "overrides": [
        {
            "files": "*.wxml",
            "options": {
                "parser": "html"
            }
        },
        {
            "files": "*.wxss",
            "options": {
                "parser": "css"
            }
        }
    ]
}
{
    "printWidth": 120,
    "tabWidth": 2,
    "useTabs": false,
    "bracketSpacing": true,
    "semi": false,
    "singleQuote": true,
    "quoteProps": "as-needed",
    "trailingComma": "none",
    "overrides": [
        {
            "files": "*.wxml",
            "options": {
                "parser": "html"
            }
        },
        {
            "files": "*.wxss",
            "options": {
                "parser": "css"
            }
        }
    ]
}
js
module.exports = {
  env: {
    es6: true,
    browser: true,
    node: true
  },
  ecmaFeatures: {
    modules: true
  },
  parserOptions: {
    ecmaVersion: 2021,
    sourceType: 'module'
  },
  globals: {
    wx: true,
    App: true,
    Page: true,
    getCurrentPages: true,
    getApp: true,
    Component: true,
    requirePlugin: true,
    requireMiniProgram: true,
    globalThis: true,
    defaultCatchError: true
  },
  extends: 'eslint:recommended',
  rules: {
    'no-multi-spaces': 'error',
    'no-trailing-spaces': 'error',
    'no-tabs': 'error',
    'no-unused-vars': 'off',
    'no-case-declarations': 'off',
    'no-console': 'off',
    'generator-star-spacing': 'off',
    'no-mixed-operators': 0,
    quotes: [
      2,
      'single',
      {
        avoidEscape: true,
        allowTemplateLiterals: true
      }
    ],
    semi: [
      2,
      'never',
      {
        beforeStatementContinuationChars: 'never'
      }
    ],
    'no-delete-var': [2],
    'object-curly-spacing': ['error', 'always'], // 对象解构两边的空格
    'array-bracket-spacing': ['error', 'never'], // 数组解构两边的空格
    'array-bracket-newline': [
      'error',
      {
        multiline: true
      }
    ],
    'eol-last': 'off',
    'func-call-spacing': [2, 'never'],
    indent: ['error', 2],
    'key-spacing': [
      'error',
      {
        beforeColon: false
      }
    ],
    'keyword-spacing': [
      'error',
      {
        before: true
      }
    ],
    'no-whitespace-before-property': 'error',
    'semi-spacing': 'error',
    'space-before-blocks': 'error',
    'space-before-function-paren': 'off',
    'space-in-parens': ['error', 'never'],
    'space-infix-ops': 'error',
    'switch-colon-spacing': 'error',
    'comma-spacing': [
      'error',
      {
        before: false,
        after: true
      }
    ],
    'dot-notation': ['error'], // 强制尽可能地使用点号
    eqeqeq: ['error', 'always'], // 要求使用 === 和 !==
    'no-dupe-keys': 'error', // 禁止对象字面量中出现重复的 key
    'arrow-spacing': 'error' // es6箭头函数空格
  }
}
module.exports = {
  env: {
    es6: true,
    browser: true,
    node: true
  },
  ecmaFeatures: {
    modules: true
  },
  parserOptions: {
    ecmaVersion: 2021,
    sourceType: 'module'
  },
  globals: {
    wx: true,
    App: true,
    Page: true,
    getCurrentPages: true,
    getApp: true,
    Component: true,
    requirePlugin: true,
    requireMiniProgram: true,
    globalThis: true,
    defaultCatchError: true
  },
  extends: 'eslint:recommended',
  rules: {
    'no-multi-spaces': 'error',
    'no-trailing-spaces': 'error',
    'no-tabs': 'error',
    'no-unused-vars': 'off',
    'no-case-declarations': 'off',
    'no-console': 'off',
    'generator-star-spacing': 'off',
    'no-mixed-operators': 0,
    quotes: [
      2,
      'single',
      {
        avoidEscape: true,
        allowTemplateLiterals: true
      }
    ],
    semi: [
      2,
      'never',
      {
        beforeStatementContinuationChars: 'never'
      }
    ],
    'no-delete-var': [2],
    'object-curly-spacing': ['error', 'always'], // 对象解构两边的空格
    'array-bracket-spacing': ['error', 'never'], // 数组解构两边的空格
    'array-bracket-newline': [
      'error',
      {
        multiline: true
      }
    ],
    'eol-last': 'off',
    'func-call-spacing': [2, 'never'],
    indent: ['error', 2],
    'key-spacing': [
      'error',
      {
        beforeColon: false
      }
    ],
    'keyword-spacing': [
      'error',
      {
        before: true
      }
    ],
    'no-whitespace-before-property': 'error',
    'semi-spacing': 'error',
    'space-before-blocks': 'error',
    'space-before-function-paren': 'off',
    'space-in-parens': ['error', 'never'],
    'space-infix-ops': 'error',
    'switch-colon-spacing': 'error',
    'comma-spacing': [
      'error',
      {
        before: false,
        after: true
      }
    ],
    'dot-notation': ['error'], // 强制尽可能地使用点号
    eqeqeq: ['error', 'always'], // 要求使用 === 和 !==
    'no-dupe-keys': 'error', // 禁止对象字面量中出现重复的 key
    'arrow-spacing': 'error' // es6箭头函数空格
  }
}
bash
node_modules
miniprogram_npm
node_modules
miniprogram_npm
AI助手