vue3 + vite

3 篇文章 0 订阅
1 篇文章 0 订阅

项目搭建

vite模板icon-default.png?t=M4ADhttps://github.com/vitejs/awesome-vite#templates请求

axios

路由

vue-router

状态

pinia

vite.config配置

   别名配置 

安装 @types/node

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
const resolve = (dir: string) => path.join(__dirname, dir)

// https://vitejs.dev/config/
export default defineConfig({
	plugins: [vue()],
	resolve: {
		alias: {
			'@': resolve('src')
		}
	}
})

添加 css 预处理器 sass

npm install -D sass sass-loader

获取 .env 配置的环境变量 

 

添加env环境变量文件, import.meta.env获取声明变量

// .env.development
// 声明变量
VITE_GLOBAL_REPLACE=true

//其他文件获取
import.meta.env.VITE_GLOBAL_REPLACE

 vite.config.ts 添加env配置文件目录   envDir: './env', 

 return defineConfig({
        plugins: [vue()],
        envDir: './env',
        resolve: {
            alias: {
                '@': resolve('src')
            }
        },
       ...
    })
添加全局 TS 类型声明 types/global.d.ts
declare global {

  export interface ViteEnv {
    VITE_ENV_NAME: string
  }
}

修改 tsconfig.json 配置项 typeRoots 和 include

{
  compilerOptions:{
    ...
     "typeRoots": ["./node_modules/@types/", "./types"],// 声明文件目录,默认时node_modules/@types
     "include": [
      "src/**/*.ts",
      "src/**/*.d.ts",
      "src/**/*.tsx",
      "src/**/*.vue", 
      "mock/**/*.ts",
      "types/**/*.d.ts",
      "types/**/*.ts",
    ]
  }
}

eslint

eslinticon-default.png?t=M4ADhttps://juejin.cn/post/7022248381095510030

依赖 

npm install --save-dev --save-exact prettier

npm install --save-dev eslint eslint-plugin-vue eslint-config-prettier

npm install @typescript-eslint/parser
 

文件配置

module.exports = {
    env: { browser: true, es2021: true, node: true },
    extends: [ 
        // 应用哪种eslint规范
        'standard',
        'prettier',
        'plugin:vue/vue3-essential',
        'plugin:vue/vue3-recommended',
        'plugin:vue/vue3-strongly-recommended'
    ],
    parserOptions: {
        ecmaVersion: 12,
        parser: '@typescript-eslint/parser',
        sourceType: 'module'
    },
    plugins: ['vue'],
    // 部分自定义规则
    rules: {
        'no-console': process.env.NODE_ENV === 'production' ? 'off' : 'error',
        'no-debugger': process.env.NODE_ENV === 'production' ? 'off' : 'error',
        'vue/max-attributes-per-line': 'off',
        'vue/html-closing-bracket-newline': 'off',
        'vue/html-closing-bracket-spacing': [
            'error',
            {
                startTag: 'never',
                endTag: 'never',
                selfClosingTag: 'always'
            }
        ]
    },
    // 全局文件声明
    globals: {
        COperationRow: 'readonly',
        Store: 'readonly',
        CAutoForm: 'readonly',
        HRRouter: 'readonly',
        NodeJS: 'readonly',
        IResponse: 'readonly',
        CSvgIcon: 'readonly',
        CStatusTabs: 'readonly',
        IWSMessage: 'readonly',
        IResponseList: 'readonly',
        ICustomAddType: 'readonly',
        IDragAndDropTarget: 'readonly',
        IRouteMeta: 'readonly',
        dayjs: 'readonly',
        ICustomExcludeType: 'readonly',
        Columns: 'readonly',
        cordova: 'readonly',
        Nullable: 'readonly',
        ElRef: 'readonly',
        ComponentRef: 'readonly',
        Recordable: 'readonly',
        EmitType: 'readonly',
        Fn: 'readonly',
        defineProps: 'readonly'
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值