基于脚手架@vue/cli 5.0.8搭建vue3项目教程

42 篇文章 0 订阅
4 篇文章 0 订阅

基于脚手架@vue/cli 5.0.8搭建vue3项目教程

前言

脚手架可以快速的帮我们搭建一个项目,而不需要我们从头开始去配置和引入插件,使用脚手架5.0.8版本创建的项目,局部webpack是5.x版本的,因此所有的配置均需要使用支持5.x版本的插件,如果出现git提交脚本不对,可以降低husky版本,或者用高版本的node来提交

  1. 使用控制台进入到项目存放目录,使用命令vue create demo创建名为demo的项目
  2. 选择自定义
    在这里插入图片描述
  3. 勾选Babel、Router、Vuex、css预处理、eslint等,如果需要ts的也可以勾选
    在这里插入图片描述
  4. 选择vue版本3.x
    在这里插入图片描述
  5. 选择n,hash模式,然后选择less作为自己的项目预处理语言
    在这里插入图片描述
  6. 选择eslint+Prettier作为eslint处理标准
    在这里插入图片描述
  7. 选择Lint on save
    在这里插入图片描述
  8. 选择config files 以配置文件的形式,方便配置
    在这里插入图片描述
  9. 至此,脚手架创建项目成功。
  10. 配置完项目后运行,发现修改代码后,总会出现一些回车的错误,可以通过配置.prettierrc文件中添加配置
{
    "tabWidth": 4,
    "singleQuote": true,
    "printWidth": 99999,
    "bracketSpacing": true,
    "trailingComma": "none",
    "endOfLine": "auto"
}
  1. 配置.eslintrc.js,其他规则可自行在rules中进行配置,配置地址https://eslint.org/docs/latest/use/configure/rules
module.exports = {
    root: true,
    env: {
        node: true
    },
    extends: ['plugin:vue/essential', 'eslint:recommended', 'plugin:prettier/recommended'],
    parserOptions: {
        parser: '@babel/eslint-parser'
    },
    rules: {
        'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
        'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
        semi: [2, 'always']
    }
};
  1. 配置在保存代码的时候自动调用eslint进行fix修复,vue.config.js文件
configureWebpack: (config) => {
	// eslint保存时自动lint
    config.plugins.map(item => {
        if (item.key === 'ESLintWebpackPlugin') {
            item.options = {
                ...item.options,
                context: path.join(__dirname, 'src'),
                extensions: ['js', 'vue', 'html'],
                fix: true,
            }
        }
    })
})
  1. 配置styleLint,https://blog.csdn.net/ta_huang/article/details/126268883
  2. 配置保存时自动调用stylelint,https://blog.csdn.net/ta_huang/article/details/130155505
  3. 配置rem自适应,安装插件 npm i postcss-px2rem -D ,配置vue.config.js文件
var px2rem = require('postcss-px2rem');
module.exports = defineConfig({
	css: {
        sourceMap: true,
        // 配置postcss-px2rem
        loaderOptions: {
            postcss: {
                postcssOptions: {
                    plugins: [postcss]
                }
            },
        }
    },
})

  1. 项目配置完成,如果需要配置gzip压缩、依赖包关系可以查看我的其他文章,有疑问可以留言,看到都会进行解答
  2. 项目架构仓库地址:https://gitee.com/huang_zhan_le/project-architecture-v2
  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值