pnpm + vue3.0 + vite + pinia + vueuse 搭建前端项目

1.安装 pnpm

使用 npm 安装

npm install -g pnpm 

注意:node 的版本号。安装 pnpm,node 的版本号不能小于 V14.19.0

查看 nvm 现在使用的 node 版本号。

nvm list 

使用 nvm 安装 node 14.19.0 版本 nvm install 14.19.0,安装完毕之后切换到此版本中nvm use 14.19.0,最好关闭之后再切。

2.初始化项目

按步骤提示初始化

  1. 输入 vite-cli 命令
pnpm create vite 
  1. 输入项目名
? Project name: invoice 
  1. 选择一个框架
? Select a framework: » - Use arrow-keys. Return to submit.
     vanilla // 原生js
 >   vue     // 默认就是 vue3
     react   // react
     preact  // 轻量化react框架
     lit     // 轻量级web组件
     svelte  // svelte框架 
  1. 使用 typescript
? Select a variant: › - Use arrow-keys. Return to submit.
     vue
 >   vue-ts 

5.启动项目

cd invoice && pnpm install && pnpm run dev 

集成配置

  1. 为保证 node 的使用
pnpm i @types/node --save-dev 
  1. 修改 vite.config.js
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import * as path from 'path';

export default defineConfig({
    resolve: {
        //设置别名
        alias: {
            '@': path.resolve(__dirname, 'src')
        }
    },
    plugins: [vue()],
    server: {
        port: 8080, //启动端口
        hmr: {
            host: '127.0.0.1',
            port: 8080
        },
        // 设置 https 代理
        proxy: {
            '/api': {
                target: 'your https address',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/api/, '')
            }
        }
    }
}); 

3.代码质量风格的统一

集成 eslint

  1. 安装
pnpm i eslint eslint-plugin-vue --save-dev 
  1. 创建配置文件: .eslintrc.js
// "off" or 0 - 关闭这个规则校验
// "warn" or 1 - 开启这个规则校验,但只是提醒,不会退出
// "error" or 2 - 开启这个规则校验,并退出

module.exports = {
  root: true,
  parserOptions: {
    ecmaVersion: 7,
    ecmaFeatures: {
      'jsx': true,
      'modules': true
    },
    parser: 'babel-eslint'
  },

  env: {
    es6: true,
    node: true
  },

  extends: [
    'eslint:recommended',
    'plugin:vue/recommended'
  ],

  plugins: ['vue'],

  globals: {
    document: false,
    navigator: false,
    window: false
  },

  rules: {
    'accessor-pairs': 2,
    'arrow-spacing': [2, {
      'before': true,
      'after': true
    }],
    'block-spacing': [2, 'always'],
    'comma-dangle': [2, 'never'],
    'comma-spacing': [2, {
      'before': false,
      'after': true
    }],
    'comma-style': [2, 'last'],
    'constructor-super': 2,
    'curly': [2, 'multi-line'],
    'dot-location': [2, 'property'],
    'eol-last': 2,
    'eqeqeq': [2, 'allow-null'],
    'generator-star-spacing': [2, {
      'before': true,
      'after': true
    }],
    'handle-callback-err': [2, '^(err|error)$'],
    'indent': [2, 2, {
      'SwitchCase': 1
    }],
    'jsx-quotes': [2, 'prefer-single'],
    'key-spacing': [2, {
      'beforeColon': false,
      'afterColon': true
    }],
    'keyword-spacing': [2, {
      'before': true,
      'after': true
    }],
    'new-cap': [2, {
      'newIsCap': true,
      'capIsNew': false
    }],
    'new-parens': 2,
    'no-array-constructor': 2,
    'no-console': 0,
    'no-caller': 2,
    'no-class-assign': 2,
    'no-cond-assign': 2,
    'no-const-assign': 2,
    'no-control-regex': 2,
    'no-delete-var': 2,
    'no-dupe-args': 2,
    'no-dupe-class-members': 2,
    'no-dupe-keys': 2,
    'no-duplicate-case': 2,
    'no-empty-character-class': 2,
    'no-empty-pattern': 2,
    'no-eval': 2,
    'no-ex-assign': 2,
    'no-extend-native': 2,
    'no-extra-bind': 2,
    'no-extra-boolean-cast': 2,
    'no-extra-parens': [2, 'functions'],
    'no-fallthrough': 2,
    'no-floating-decimal': 2,
    'no-func-assign': 2,
    'no-implied-eval': 2,
    'no-inner-declarations': [2, 'functions'],
    'no-invalid-regexp': 2,
    'no-irregular-whitespace': 2,
    'no-iterator': 2,
    'no-label-var': 2,
    'no-labels': [2, {
      'allowLoop': false,
      'allowSwitch': false
    }],
    'no-lone-blocks': 2,
    'no-mixed-spaces-and-tabs': 2,
    'no-multi-spaces': 2,
  • 9
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值