当前位置: 首页 > Web前端 > vue.js

vite开箱即用的使用和特性

时间:2023-03-31 20:26:45 vue.js

vite几个特性:快速冷启动即时模块热更新真正的按需编译fastbuildnpmcreatevite-appproject-namenpminpmrundev可以看到生成的目录非常简洁index.html的变化是导入入口文件的方式,让main.js可以使用ES6Module方式来组织代码。vite中可以直接导入.css文件,样式会影响导入的页面,最终会打包成style.css。image.pngeslint的使用使用eslint规范项目代码,通过prettier对代码进行格式化。首先在项目中安装依赖,配置eslintrules.eslintrc.jsmodule.exports={root:true,env:{node:true,},extends:["plugin:vue/vue3-essential","eslint:recommended",“@vue/prettier”],parserOptions:{parser:“babel-eslint”,},rules:{“no-console”:process.env.NODE_ENV===“production”?“警告”:“关闭”,“无调试器”:process.env.NODE_ENV===“生产”?"warn":"off","prettier/prettier":["warn",{//singleQuote:none,//semi:false,trailingComma:"es5",},],},};如果需要,可以配置prettier.config.js修改prettier的默认格式化规则module.exports={printWidth:80,//每行代码的长度(默认80)tabWidth:2,//每个tab有多少个空格相当于(默认2)useTabs:false,//是否使用制表符进行缩进(默认false)singleQuote:false,//使用单引号(默认false)semi:true,//在末尾使用分号statement(defaulttrue)trailingComma:'es5',//对多行使用尾随逗号(默认无)bracketSpacing:true,//在对象文字的大括号之间使用空格(默认true)jsxBracketSameLine:false,//The>in多行JSX放在最后一行的末尾而不是开始新行(默认false)arrowParens:"avoid",//只有一个参数的箭头函数的参数是否带括号(默认避免)};configurealias为src/components定义一个别名,vite.config.jsconstpath=require("path");module.exports={alias:{//路径映射必须以/开头,以"/comps/"结尾:path.resolve(__dirname,"src/components"),},};使用此别名从“/comps/CourseAdd.vue”导入CourseAdd;从“/comps/Comp.vue”导入Comp;