* vite是什么?
* 一个前端的开发构建工具
* 当我们的项目组件变大时,会自觉的分文件、分组件等操作,缩减单文件的大小、增加可维护性,vite则可以帮我们管理,并且它有很多插件帮助我们开发。
目录
初始化
- 创建一个文件夹,比如这里创建一个叫 mimicrymusic 的文件夹:
- 然后进入这个文件夹,或是把它拖进vscode中:
- 可以进VSCode内,使用终端运行以下命令:
- 初始化生成包配置文件:npm init -y
- 生成package.json:
- -
- 内容如下:
- -
- 其中:
- name:项目名
- version:版本号
- description:项目描述
- main:js入口
- scripts:配置用于npm的命令
- keywords:(可以不要)
- author:作者信息(可以不要)
- license:开源协议
安装vite依赖
- 在终端中执行命令:npm i vite -D
- 安装vite的开发环境依赖:
- 等待一段时间的下载:
- 下载完成后我们刚刚的包配置文件package.json中就会有自动增加一个vite的依赖:
安装vue的依赖
- 在终端中执行命令:npm i vue
- 等待安装完成以后,package.json中就会自动增加vue的配置:
创建index.html
- 在项目的根位置,即和package.json同级的位置创建一个index.html文件:
- 里面写如下内容:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>标题</title>
</head>
<body>
<!-- 引用的js文件位置 -->
<script type="module" src=""></script>
</body>
</html>
- 正如上面代码中注释所说,script标签引入了一个js文件到index.html,但我们还没有指定引入哪一个js文件,下面我们将创建这个文件,然后在引入。
创建main.js
- 在项目根位置创建src目录,然后在src内创建main.js文件:
- 里面我们可以先随便写一句输出: console.log("hello coolight");
- 保存文件
- 在我们刚刚的index.html中引入main.js文件:
<!-- 引用的js文件 -->
<script type="module" src="./src/main.js"></script>
- 在package.json中配置npm命令,即把里面的scripts的内容改为 "dev" : "vite"
尝试让它跑起来(1)
- 在终端中敲 npm run dev,就会有如下信息提示
- 键盘按住ctrl,然后鼠标左键点击终端里图中框起来的链接(不要点我的图,点你的终端里的!!!):
- 它就会跳转到浏览器,显示我们刚刚写的页面
- 一片空白则是正常的,因为我们的页面并没有写东西
- 我们的js也只写了一句输出,这时候要在浏览器中打开控制台看看有没有这句输出
- 浏览器中来到我们写的页面
- 在浏览器中按一下键盘F12键
- 浏览器就会弹出一个窗口:
- 此时点击控制台,就可以看见我们的main.js的输出了:
创建App.vue
- 在src目录下,新建 App.vue 文件:
- 内容可以随便写点,比如:
<template>
<div>
你好 coolight
</div>
</template>
在main.js中创建vue,安装vitejs
- 修改main.js的内容为:
import { createApp } from 'vue'
import App from './App.vue'
const app = createApp(App)
app.mount('#app')
- 可以看到,我们在main.js中创建的vue需要一个挂载点,在html中一个id为 app 的元素
- 所以我们需要在index.html中增加一个 <div id="app"></div> :
- 保存文件
- 此时你可能发现,欸vite好像报错了:
- [vite] Internal server error: Failed to parse source for import analysis because the content contains invalid JS syntax. Install @vitejs/plugin-vue to handle .vue files.
- 浏览器里我们的页面也有报错:
- 它的意思很明显,需要我们去安装 @vitejs/plugin-vue,因为浏览器正常执行不了vue文件,所以需要安装插件来编译解析。
- 那么我们就来安装它。
- 如果你的终端vite还在运行,也就是没有显示提示让你输入,就像这样:
- 那么就按键盘ctrl + c ,停止掉vite
- 它会问你 终止批处理操作吗(Y/N)?
- 我们输入 y ,然后回车即可
- 然后再输入 npm i @vitejs/plugin-vue -D
- 等待下载安装:
- 然后在项目根目录创建vite的配置文件:vite.config.js
- 里面写如下配置:
import { defineConfig } from "vite"
import Vue from "@vitejs/plugin-vue"
export default defineConfig({
plugins:[
Vue()
]
})
- 保存文件
- 在终端中执行 npm run dev
- 然后回到浏览器中看看我们的页面,就会发现已经正常了!
结语
- 这个是手动配置的方法,其实有很简单的一键操作。
- 后面我们聊聊给手动配置路由router,状态管理pinia等
Здравствуйте!
Заказать диплом о высшем образовании.
cchs.ru/forums/topic/kupit-diplomy-s-polnoj-garantiej-kachestva/
Успешной учебы!
гибкие гимнастки порно http://www.sexygimnastky.ru .
Официальная покупка диплома вуза с сокращенной программой обучения в Москве
ast-diplomas.com/kupit-diplom-voronezh
buy cipro without rx: buy cipro without rx – where to buy cipro online
Привет!
Где заказать диплом по необходимой специальности?
vitroshop.ru/index.html
Indibet is a premier online casino offering a wide array of games including slots, table games, and live dealer options. Renowned for its user-friendly interface and robust security measures, Indibet ensures a top-notch gaming experience with exciting bonuses and 24/7 customer support.
купить квартиру недорого https://kvartiru-kupit43.ru
купить квартиру от застройщика https://kvartira-new43.ru
квартиру новостройку жк купить купить квартиру от застройщика
paxlovid covid: Paxlovid over the counter – Paxlovid over the counter
You’re so cool! I do not suppose I’ve truly read through a single thing like this before. So good to find another person with a few unique thoughts on this issue. Seriously.. many thanks for starting this up. This site is one thing that’s needed on the internet, someone with a little originality.
buy ciprofloxacin over the counter: antibiotics cipro – ciprofloxacin order online
Здравствуйте!
Мы можем предложить дипломы психологов, юристов, экономистов и других профессий по выгодным тарифам.
prikol100500.ru/vash-diplom-byistro-nadezhno-kachestvenno
bookmarked!!, I love your site.
The future football star Shabab Al-Ahly https://dubai.shabab-al-ahli-ar.com was born in Dubai in 2000. From a young age, he showed exceptional football abilities and joined the youth academy of one of the UAE’s leading clubs, Shabab Al-Ahly.
how to buy generic clomid: order generic clomid pill – can i purchase clomid without prescription
Добрый день!
Мы можем предложить дипломы любой профессии.
phugiabetong.vn/купить-диплом-в-березниках
Всегда вам поможем!.
In the world of football, Atletico Madrid https://spain.atletico-madrid-ar.com has long been considered the second most important club in Spain after the dominant, Real Madrid.
The fascinating story of Ja Morant’s https://spain.atletico-madrid-ar.com meteoric rise, from status from rookie to leader of the Memphis Grizzlies and rising NBA superstar.
Galatasaray https://turkey.galatasaray-ar.com is one of the most famous football clubs in Turkiye, with a glorious and eventful history.
Здравствуйте!
Купить диплом любого университета.
stroyk.bestbb.ru/viewtopic.php?id=421#p513
Успешной учебы!
порно секс с училкой порно секс с училкой .
порно видео тренер порно видео тренер .
секс училки и ученика https://sex-s-uchilkami.ru .
смотреть секс с училкой http://www.sex-s-uchilkami.ru .
порно тренер выебал порно тренер выебал .
видео секс с училкой видео секс с училкой .
порно тренер трахнул девушку http://pornotrenery.ru/ .
порно тренер трахает порно тренер трахает .
видео секс с училкой видео секс с училкой .
секс с училкой бесплатно https://sex-s-uchilkami.ru .
секс училки и ученика sex-s-uchilkami.ru .
порно личный тренер порно личный тренер .
порно онлайн тренер порно онлайн тренер .
секс с сексуальной училкой sex-s-uchilkami.ru .
порно онлайн тренер порно онлайн тренер .
Добрый день!
Заказать диплом любого университета.
true.pahom.su/2024/07/04/kak-nayti-nadezhnyy-magazin-s-obshirnym-vyborom-diplomov.html
Добрый день!
Заказать диплом университета.
l67697qa.beget.tech/2024/07/04/ogromnyy-assortiment-dokumentov-v-populyarnom-internet-magazine.html
Добрый день!
Приобрести диплом ВУЗа.
xleks.ru/2024/07/04/shirokiy-katalog-dokumentov-v-znamenitom-internet-magazine.html
AC Milan https://italy.milan-ar.com is one of the most successful and decorated football clubs in the world.
Ремонт плоской кровли https://remontiruem-krovly.ru в Москве, цена работы за 1 м?. Прайс лист на работы под ключ, отзывы и фото.
наклейки на заказ https://salavat-rik.ru
Здравствуйте!
Купить документ о получении высшего образования можно у нас в Москве.
ast-diplom24.ru/kupit-diplom-o-srednem-obrazovanii
Хорошей учебы!
Thai Company Directory https://thaicorporates.com List of companies and business information.
ciprofloxacin 500 mg tablet price: buy cipro – buy cipro online without prescription
where can i buy clomid without prescription: can you buy cheap clomid now – how to buy cheap clomid no prescription
купить диплом о среднем образовании в новокузнецке mandiplomik.ru .
Привет!
Купить документ о получении высшего образования вы имеете возможность у нас.
ast-diplomas.com/kupit-diplom-perm
Добрый день!
Приобрести диплом любого ВУЗа.
licomklicu.ru/read-blog/885
Добрый день!
Приобрести диплом университета.
amengram.com/blogs/355/%D0%9B%D0%B5%D0%B3%D0%BA%D0%B8%D0%B9-%D0%BF%D0%BE%D0%B8%D1%81%D0%BA-%D0%BE%D0%BD%D0%BB%D0%B0%D0%B9%D0%BD-%D0%BC%D0%B0%D0%B3%D0%B0%D0%B7%D0%B8%D0%BD%D0%B0-%D1%87%D1%82%D0%BE-%D1%80%D0%B5%D0%B0%D0%BB%D0%B8%D0%B7%D1%83%D0%B5%D1%82-%D0%B4%D0%B8%D0%BF%D0%BB%D0%BE%D0%BC%D1%8B