• day1项目配置


    项目初始化

    1. 本项目使用vite进行构建,vite参考官网
    2. pnpm包管理:performant npm,意味"高性能的npm"。pnpm由npm/yarn衍生而来,解决了npmlyarn内部潜在的bug,极大的优化了性能,扩展了使用场景。被誉为"最先进的包管理工具”

    0|1使用vite创建V3工程

    是新一代前端构建工具

    官网地址

    image-20230921011659815

    pnpm安装指令

    npm i -g pnpm

    项目初始化

    cmd进入命令行构建vite项目

    image-20230921012142204

    pnpm create vite

    image-20230921012505315

    进入项目根目录,也就是我们的waves-ts-runtine根目录下

    image-20230921012544865

    pnpm i

    image-20230921012709766

    运行demo

    image-20230921012750599

    访问5173端口

    image-20230921012816276

    0|2项目配置eslint

    image-20230921080218682

    设置项目运行时,浏览器自动打开

    image-20230921080516802

    安装eslint

    pnpm i eslint -D

    image-20230921080810821

    生成配置文件:eslint --lint

    目的:告诉eslint,你应该如何工作

    npx eslint --init

    image-20230921080928088

    image-20230921081004714

    image-20230921081017730

    image-20230921081044594

    image-20230921081100640

    image-20230921081125611

    image-20230921081152018

    image-20230921081424542

    项目当中出现了这个文件夹image-20230921081517126

    eslintrc.cjs参数解析

    1. env:工作环境:浏览器,校验的是es语法
    2. extends:规则的继承
    3. ......

    1|0Vue3环境代码校验插件

    image-20230921082111349

    安装代码

    pnpm install -D eslint-plugin-import eslint-plugin-vue eslint-plugin-node eslint-plugin-prettier eslint-config-prettier eslint-plugin-node @babel/eslint-parser

    image-20230921082625039

    修改eslint配置文件

    // @see https://eslint.bootcss.com/docs/rules/ module.exports = { env: { browser: true, es2021: true, node: true, jest: true, }, /* 指定如何解析语法 */ parser: 'vue-eslint-parser', /** 优先级低于 parse 的语法解析配置 */ parserOptions: { ecmaVersion: 'latest', sourceType: 'module', parser: '@typescript-eslint/parser', jsxPragma: 'React', ecmaFeatures: { jsx: true, }, }, /* 继承已有的规则 */ extends: [ 'eslint:recommended', 'plugin:vue/vue3-essential', 'plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended', ], plugins: ['vue', '@typescript-eslint'], /* * "off" 或 0 ==> 关闭规则 * "warn" 或 1 ==> 打开的规则作为警告(不影响代码执行) * "error" 或 2 ==> 规则作为一个错误(代码不能执行,界面报错) */ rules: { // eslint(https://eslint.bootcss.com/docs/rules/) 'no-var': 'error', // 要求使用 let 或 const 而不是 var 'no-multiple-empty-lines': ['warn', { max: 1 }], // 不允许多个空行 'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off', 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off', 'no-unexpected-multiline': 'error', // 禁止空余的多行 'no-useless-escape': 'off', // 禁止不必要的转义字符 // typeScript (https://typescript-eslint.io/rules) '@typescript-eslint/no-unused-vars': 'error', // 禁止定义未使用的变量 '@typescript-eslint/prefer-ts-expect-error': 'error', // 禁止使用 @ts-ignore '@typescript-eslint/no-explicit-any': 'off', // 禁止使用 any 类型 '@typescript-eslint/no-non-null-assertion': 'off', '@typescript-eslint/no-namespace': 'off', // 禁止使用自定义 TypeScript 模块和命名空间。 '@typescript-eslint/semi': 'off', // eslint-plugin-vue (https://eslint.vuejs.org/rules/) 'vue/multi-word-component-names': 'off', // 要求组件名称始终为 “-” 链接的单词 'vue/script-setup-uses-vars': 'error', // 防止