vite创建项目及设置alias用@代替src失败的解决方法

1,使用vite创建项目   
  npm create vite@latest 
2,选择脚手架配置
  project name:  bigscreen
  select a framework:> Vue
  select a variant: > Javascript
3, 跳转到项目目录 cd bigscreen
4,安装 项目依赖  npm i
5,Install Tailwind CSS with Vite
    npm install -D tailwindcss@3 postcss autoprefixer
    npx tailwindcss init -p
  Configure your template paths 配置 tailwind.config.js
  /** @type {import('tailwindcss').Config} */
export default {
  content: [
    "./index.html",
    "./src/**/*.{js,ts,jsx,tsx}",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}
Add the Tailwind directives to your CSS
Add the @tailwind directives for each of Tailwind’s layers to your ./src/index.css file
@tailwind base;
@tailwind components;
@tailwind utilities;

6,运行项

### 创建基于 ViteVue 项目 #### 准备工作 为了创建一个新的基于 ViteVue 项目,可以采用 npm 或 yarn 来执行创建命令。对于希望使用 TypeScript 和 Vue 组合的开发者来说,可以通过如下命令快速初始化项目结构: ```bash npm create vite@latest my-vue3-project --template vue-ts ``` 或者如果偏好 Yarn,则可使用此命令[^1]: ```bash yarn create vite my-vue3-project --template vue-ts ``` 上述命令会引导用户完成一系列配置选项的选择过程,包括但不限于指定项目名称以及挑选前端框架等操作[^2]。 #### 安装依赖项 一旦项目模板被成功下载并放置到本地目录下之后,下一步就是安装必要的依赖包。这一步骤通常通过运行 `npm install` 或者 `yarn install` 实现,具体取决于之前选用的包管理器工具。 #### 启动开发服务器 当所有的准备工作都完成后,就可以启动开发环境了。Vite 提供了一个非常高效的热更新机制,在首次加载应用时仅编译所需的模块,并且后续修改也会即时反映出来而无需重新构建整个应用程序。这种特性使得开发体验更加流畅高效[^3]。 #### 配置优化 针对更复杂的场景需求,可能还需要进一步调整项目的配置文件 `vite.config.ts` 。例如设置别名路径简化 imports 路径书写方式: ```typescript import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' export default defineConfig({ plugins: [vue()], resolve: { alias: [ { find: "@", replacement: "/src" } ] } }) ``` 这段代码定义了一个简单的别名映射关系,允许在源码中以 `@/components/Button.vue` 这样的形式代替冗长的实际物理路径[^4]。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值