vue2企业级项目(一)

news/2024/4/27 10:25:56/文章来源:https://blog.csdn.net/m0_45291815/article/details/131988197

vue2企业级项目(一)

创建项目,并创建项目编译规范

1、node 版本

由于是vue2项目,所以 node 版本比较低。使用 12.18.3 左右即可

2、安装vue

安装指定版本的vue2

npm i -g vue@2.7.10
npm i -g @vue/cli@4.4.6

3、编辑器规范

  1. vscode安装 EditorConfig for VS Code插件

  2. 项目根目录创建 .editorconfig文件

  3. 填写一下示例内容

    # 表示是最顶层的配置文件,发现值为true时,才会停止查找.editorconfig文件
    root = true# 表示配置所有的文件
    [*]
    # utf-8格式
    charset = utf-8
    # 缩进为2个空格
    indent_style = space
    indent_size = 2
    # 结尾都是用crlf格式, 并且文件保存是结尾换行
    end_of_lint = crlf
    insert_final_newline = true
    # 移除无效空格
    trim_trailing_whitespace = true# 表示配置所有的md文件
    [*.md]
    insert_final_newline = true
    trim_trailing_whitespace = true

4、prettier

4、prettier

  1. vscode安装 Prettier - Code formatter插件

  2. 项目安装插件

    npm install --save-dev prettier@1.18.2
    
  3. 项目根目录创建.prettierignore文件

    dist/*
    node_modules/*
    packages/*
    public/*
  4. 项目根目录创建.prettierrc文件

    {"arrowParens": "always","bracketSpacing": true,"endOfLine": "crlf","htmlWhitespaceSensitivity": "ignore","ignorePath": ".prettierignore","jsxBracketSameLine": false,"jsxSingleQuote": false,"printWidth": 80,"quoteProps": "as-needed","semi": true,"singleQuote": false,"tabWidth": 2,"trailingComma": "all","useTabs": false,"vueIndentScriptAndStyle": false
    }
    
  5. 添加启动命令到package.json

    "script": {..."format": "prettier --write \"src/**/*.js\" \"src/**/*.vue\"",
    }
    

5、eslint

  1. vscode安装 Eslint插件

  2. 项目下载依赖

    npm install --save-dev eslint-config-prettier@8.8.0 eslint-plugin-prettier@5.0.0
    
  3. 根目录创建.eslintignore文件

    dist/*
    node_modules/*
    packages/*
    public/*
  4. 根目录创建.eslintrc.js文件

    module.exports = {root: true,env: {node: true,},extends: ["plugin:vue/essential","eslint:recommended","plugin:prettier/recommended",],parserOptions: {ecmaVersion: 2020,},rules: {"array-callback-return": "error","arrow-parens": "error","arrow-spacing": ["error",{before: true,after: true,},],"comma-dangle": ["error", "always-multiline"],"object-curly-spacing": ["error", "always"],"key-spacing": ["error", { beforeColon: false, afterColon: true }],"comma-spacing": ["error",{before: false,after: true,},],indent: ["error",2,{SwitchCase: 1,},],"for-direction": "error","keyword-spacing": ["error",{before: true,after: true,},],"no-console": process.env.NODE_ENV === "production" ? "warn" : "off","no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off","no-extra-semi": "error","no-multi-spaces": "error","no-multiple-empty-lines": ["error",{max: 3,maxEOF: 1,maxBOF: 1,},],"prettier/prettier": "off",quotes: ["error", "double"],"semi-spacing": ["error",{before: false,after: true,},],"semi-style": ["error", "last"],semi: ["error","always",{omitLastInOneLineBlock: true,},],"space-after-keywords": [0, "always"],"space-infix-ops": "error","spaced-comment": ["error","always",{block: {exceptions: ["*"],balanced: true,},},],},
    };
  5. 添加启动命令到package.json

    "script": {...,"eslint:fix": "eslint src/**/* --ext .js,.vue",
    }
    

6、stylelint

  1. vscode安装stylelint插件

  2. 项目安装依赖

    npm install --save-dev stylelint@15.3.0 stylelint-config-recommended@11.0.0 stylelint-config-recommended-vue@1.4.0 stylelint-config-recommended-vue@1.4.0 stylelint-config-standard@25.0.0 stylelint-config-prettier@9.0.5 stylelint-order@5.0.0 stylelint-less postcss-html postcss-less@4.0.0 less-loader@4.1.0 less@4.1.3
    
  3. 根目录创建.stylelintignore文件

    dist/*
    node_modules/*
    packages/*
    public/*
    
  4. 根目录创建.stylelintrc.js文件

    module.exports = {extends: ["stylelint-config-recommended","stylelint-config-standard","stylelint-config-recommended-vue","stylelint-config-html","stylelint-config-prettier",],plugins: ["stylelint-order", "stylelint-less"],ignorePath: ".stylelintignore",overrides: [{files: ["**/*.{html,vue}"],customSyntax: "postcss-html",},{files: ["**/*.less"],customSyntax: "postcss-less",},],rules: {"declaration-block-no-duplicate-properties": [true,{ignore: "consecutive-duplicates",},],indentation: 2,"selector-pseudo-element-no-unknown": [true,{ignorePseudoElements: ["v-deep"],},],"number-leading-zero": "never","no-descending-specificity": null,"font-family-no-missing-generic-family-keyword": null,"selector-type-no-unknown": null,"at-rule-no-unknown": null,"no-duplicate-selectors": null,"no-empty-source": null,"block-no-empty": true,"max-nesting-depth": null,"max-line-length": null,"selector-max-compound-selectors": null,"selector-no-qualifying-type": null,"selector-class-pattern": null,"function-no-unknown": null,"function-parentheses-newline-inside": null,"alpha-value-notation": "number","no-empty-first-line": true,"order/properties-order": ["width","min-width","max-width","height","min-height","max-height","position","top","right","bottom","left","z-index","display","flex-wrap","justify-content","align-items","float","clear","overflow","overflow-x","overflow-y","padding","padding-top","padding-right","padding-bottom","padding-left","margin","margin-top","margin-right","margin-bottom","margin-left","font-size","font-family","font-weight","text-justify","text-align","text-indent","text-align","text-overflow","text-decortion","white-space","color","background","background-position","background-repeat","background-size","background-color","background-clip","border","border-style","border-width","border-color","border-top-style","border-top-width","border-top-color","border-right-style","border-right-width","border-right-color","border-bottom-style","border-bottom-width","border-bottom-color","border-left-style","border-left-width","border-left-color","border-radius","opacity","filter","list-style","outline","visibility","box-shadow","text-shadow","resize","trasition",],"selector-pseudo-class-no-unknown": [true,{ ignorePseudoClasses: ["global"] },],},
    };
  5. 添加启动命令到package.json

    "script": {...,"stylelint:fix": "stylelint src/**/*.{html,vue,less} --fix",
    }
    
  6. vscode配置文件新增内容如下

    ...
    "editor.codeActionsOnSave": {"source.fixAll.stylelint": true
    },
    "stylelint.validate": ["vue", "less", "css", "html", "scss", "sass"]
    

7、可选链

  1. 项目安装依赖

    npm install --save-dev @babel/core @babel/preset-env @babel/plugin-proposal-optional-chaining @babel/plugin-proposal-nullish-coalescing-operator
  2. 项目根目录babel.config.js修改如下

    module.exports = {presets: ["@vue/cli-plugin-babel/preset"],plugins: ["@babel/plugin-proposal-optional-chaining","@babel/plugin-proposal-nullish-coalescing-operator",],
    };
    

8、commitlint

  1. 执行命令

    vue add commitlint
    
  2. 下载依赖

    npm install --save-dev lint-staged@9.5.0
    
  3. 修改package.json配置

    ...
    "husky": {"hooks": {"pre-commit": "lint-staged","commit-msg": "commitlint -E HUSKY_GIT_PARAMS"}},"lint-staged": {"*.{js,vue}": ["vue-cli-service lint ./src --fix","prettier --write ./src","git add"]}
    

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.luyixian.cn/news_show_337202.aspx

如若内容造成侵权/违法违规/事实不符,请联系dt猫网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

layui框架学习(33:流加载模块)

Layui中的流加载模块flow主要支持信息流加载和图片懒加载两部分内容,前者是指动态加载后续内容,示例的话可以参考csdn个人博客主页,鼠标移动到页面底部时自动加载更多内容,而后者是指页面显示图片时才会延迟加载图片信息。   fl…

记录vue的一些踩坑日记

记录vue的一些踩坑日记 安装Jq npm install jquery --save vue列表跳转到详情页,再返回列表的时候不刷新页面并且保持原位置不变; 解决:使用keepAlive 在需要被缓存的页面的路由中添加:keepAlive: true, {path: /viewExamine,nam…

怎么在线修改图片?分享一个图片修改工具

无论是在个人或商业领域,我们都需要使用高质量的图片来传达信息或提高品牌形象。大尺寸的图片也会占据大量的存储空间和带宽,影响网站的加载速度和用户体验。因此,我们需要一种高效的工具来解决这个问题。今天向大家介绍一款非常实用的图片处…

Android 开发代码规范

一. AndroidStudio开发工具规范 使用最新的稳定版本.统一文件的编码格式为utf-8. 清除每个类里面的无效的import导包.代码样式统一,比如,tab缩进4个空格,或者 tab size等如果没有特殊情况使用默认的配置即可。每行字数每行字符数不得超过 160 字符&…

C++--菱形继承

1.什么是菱形继承 单继承:一个子类只有一个直接父类时称这个继承关系为单继承 多继承:一个子类有两个或以上直接父类时称这个继承关系为多继承 菱形继承的问题:菱形继承有数据冗余和二义性的问题,数据冗余是由于创建多个相同类型的…

SpringBoot 如何进行 统一异常处理

在Spring Boot中,可以通过自定义异常处理器来实现统一异常处理。异常处理器能够捕获应用程序中抛出的各种异常,并提供相应的错误处理和响应。 Spring Boot提供了ControllerAdvice注解,它可以将一个类标记为全局异常处理器。全局异常处理器能…

Glow: Generative Flow with Invertible 1×1 Convolutions论文解析及实现(二)

Glow: Generative Flow with Invertible 11 Convolutions 代码github: https://github.com/rosinality/glow-pytorch添加链接描述 1 模型架构如下 1.1 左边图flow模型 Flow model ① ActNorm ② InvConv2dLU ③ AffineCoupling 1.2 右边模型结构Glow模型 Glow Model Block…

万年历【小游戏】(Java课设)

系统类型 Java实现的小游戏 使用范围 适合作为Java课设!!! 部署环境 jdk1.8Idea或eclipse 运行效果 更多Java课设系统源码地址:更多Java课设系统源码地址 更多Java小游戏运行效果展示:更多Java小游戏运行效果展…

解决Font family [‘sans-serif’] not found问题

序言 以下测试环境都是在 anaconda3 虚拟环境下执行。 激活虚拟环境 conda activate test_python_env 或 source activate test_python_env工具: WinSCP Visual Studio Code 这里笔者使用 WinSCP 工具连接,编辑工具是 Visual Studio Code 一、字体…

mysql(六)读写分离

目录 前言 一、概述 二、配置JAVA环境及安装阿米巴 三、配置阿米巴 四、测试 总结 前言 MySQL读写分离是一种常见的数据库架构设计模式,旨在提高系统的性能和可用性。它通过将读操作和写操作分离到不同的MySQL实例上来实现。 读写分离的原理是: 1. 主…

UE5.1.1 创建C++项目失败

因一直使用Unity开发环境,安装Unreal后,并未详细配置过其开发环境,默认创建蓝图工程无异常,但创建UE C项目时总共遇到两个错误: 错误一 Running /Epic/UE/UE_5.1/Engine/Build/BatchFiles/Build.bat -projectfiles -…

郑州主域名和多个子域名的泛域名https证书

随着网络的发展,一个站长往往会创建多个域名网站,为了与主站有联系,站长会选择主站域名的二级域名来创建网站,比如主站是www .***. com,那么新创建的网站的域名就是top .***. com、vip .***. com等。 1.在安装部署htt…

原生求生记:揭秘UniApp的原生能力限制

文章目录 1. 样式适配问题2. 性能问题3. 原生能力限制4. 插件兼容性问题5. 第三方组件库兼容性问题6. 全局变量污染7. 调试和定位问题8. 版本兼容性问题9. 前端生态限制10. 文档和支持附录:「简历必备」前后端实战项目(推荐:⭐️⭐️⭐️⭐️…

利用小波包对一维信号进行降噪或压缩(MATLAB)

function [ output_args ] example4_12( input_args ) %EXAMPLE4_12 Summary of this function goes here % Detailed explanation goes here clc; clear; % 设置信噪比和随机数的初始值 snr 3; init 2055615866; % 生成一个原始信号xref和含高斯白噪声的信号x [xref,x] …

网络安全/信息安全(黑客技术)自学笔记

一、网络安全基础知识 1.计算机基础知识 了解了计算机的硬件、软件、操作系统和网络结构等基础知识,可以帮助您更好地理解网络安全的概念和技术。 2.网络基础知识 了解了网络的结构、协议、服务和安全问题,可以帮助您更好地解决网络安全的原理和技术…

2023年的深度学习入门指南(22) - 百川大模型13B的运行及量化

2023年的深度学习入门指南(22) - 百川大模型13B的运行及量化 不知道上一讲的大段代码大家看晕了没有。但是如果你仔细看了会发现,其实代码还是不全的。比如分词器我们就没讲。 另外,13B比7B的改进点也没有讲。 再有,对于13B需要多少显存我们…

记录每日LeetCode 141.环形链表 Java实现

题目描述: 给你一个链表的头节点 head ,判断链表中是否有环。 如果链表中有某个节点,可以通过连续跟踪 next 指针再次到达,则链表中存在环。 为了表示给定链表中的环,评测系统内部使用整数 pos 来表示链表尾连接到链…

【RTT驱动框架分析00】-应用层函数调用流程-串口为例

应用层函数调用流程分析以-串口为例 1. rt_device_find调用流程 RTT内部有一个全局变量数组rt_object_container数组的数量就是 rt_object_info_type 内核对象的种类,其中包含一个RT_USING_DEVICE (设备的数据类型),数组内部的每一个变量包含一个链表&…

基于扩展(EKF)和无迹卡尔曼滤波(UKF)的电力系统动态状态估计(Matlab代码实现)

💥💥💞💞欢迎来到本博客❤️❤️💥💥 🏆博主优势:🌞🌞🌞博客内容尽量做到思维缜密,逻辑清晰,为了方便读者。 ⛳️座右铭&a…

C\C++内存管理

目录 1.C/C内存分布2.C语言中动态内存管理方式3.C中动态内存管理3.1new/delete内置类型3.2new和delete操作自定义类型 4.operator new与operator delete函数4.2重载operator new与operator delete(了解) 5.new和delete的实现原理5.1内置类型5.2 自定义类…