# FrontNewLibDemoProject **Repository Path**: wangzz_felix/front-new-lib-demo-project ## Basic Information - **Project Name**: FrontNewLibDemoProject - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-02-24 - **Last Updated**: 2024-05-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Vue环境针对新技术进行落地测试Demo #### Vue Grid Layout: - https://jbaysolutions.github.io/vue-grid-layout/zh/guide/01-basic.html ~~- h~~ttps://jbaysolutions.github.io/vue-grid-layout/zh/guide/11-bounded.html #### chinese-lunar-calendar #### dom-to-image #### preview #### size-sensor #### vue-fullscreen #### vue draggable #### pinia https://pinia.vuejs.org/zh/ #### Vite相关 NPM依赖解析和预构建 1. 预构建可提高页面加载速度,并将CommonJS/UMD转换为ESM格式,预构建由esbuild执行 2. /node_modules/.vite/deps/my-dep.js?v=f3sf2ebd 依赖是强缓存,Vite在HTTP头来缓存请求得到的依赖 依赖预构建 Vite执行时 =》 依赖项构建 1. CommonJS和UMD兼容性:开发阶段中,Vite的开发服务器将所有代码视为原生ES模块 Vite必须将以CommonJS或UMD形式提供的依赖项转换为ES模块 2. 在转换CommonJS依赖项的时候,Vite会先进行智能导入分析 ```js import React, { useState } from 'react' ``` #### 静态资源处理 ```js import imgUrl from './img.png' imgUrl - /img.png 开发中 - /assets/img.2d8efhg.png 构建之后 ``` #### public - 不会被源码引用 eg: robots.txt - 不会被hash #### 环境变量 Vite特殊的 import.meta.env对象上暴露环境变量 ```js * import.meta.env.MODE: {string}应用运行的模式 development/production * import.meta.env.BASE_URL: {string}部署应用的时候基本URL * import.meta.env.PROD: {boolean} 判断应用是否在生产环境 * import.meta.env.DEV: {boolean} 判断应用是否在开发环境 * import.meta.evn.SSR: {boolean} 应用是否在serve上 ``` #### evn文件 ```js .env # 所有情况下都会加载 .env.local # 所有情况都会加载, 但git忽略 .env.[mode] # 只在指定模式下加载 .env.[mode].local # 只在指定模式下加载,但会被 git 忽略 优先级 .env.production > .evn ``` #### 业务逻辑分离 ```js 将业务逻辑提取到独立的useUserData函数中 // useUserData.js // UserProfile.vue // 业务逻辑分离 function UserProfile() { const user = useUserData() // 独立服务获取用户数据 return (

{user.name}

{user.email}

) } ```