* 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等
vid-st internet-magazin-strojmaterialov.ru .
http://clomiddelivery.pro/# where can i buy generic clomid now
Al-Nasr Club https://saudi.al-hilal-ar.com from Riyadh has a rich history of success, but its growth has been particularly impressive in recent years.
Al-Ittihad https://saudi.al-ittihad-ar.com is one of the most famous football clubs in Saudi Arabia. Founded in 1927, the Saudi football giant has come a long way to the pinnacle of success.
Good article! We will be linking to this particularly great article on our site. Keep up the good writing.
интернет магазин стройматериалов интернет магазин стройматериалов .
Al-Nasr https://saudi.al-nassr-ar.com is one of the most famous football teams in the Kingdom of Saudi Arabia.
cost of amoxicillin 30 capsules: amoxicillin price canada – amoxicillin 500mg price
Привет!
Приобрести диплом любого университета.
naturetour.ru/club/user/19/blog/1594/
порно коллекции бесплатно https://porn-library.ru .
Luis Suarez https://inter-miami.luis-suarez-ar.com the famous Uruguayan footballer, ended his brilliant career in European clubs and decided to try his hand at a new challenge – Major League Soccer.
Добрый день!
Мы изготавливаем дипломы любых профессий по приятным тарифам.
standart-rzn.ru/kvartiry-i-mkd/vychet-na-pokupku-doma-s-uchastkom.html
порно коллекции бесплатно https://www.porn-library.ru .
скачать порно коллекций https://porn-library.ru .
порно видео порно видео .
скачать порно коллекций https://porn-library.ru .
смотреть порно видео смотреть порно видео .
топовые порно видео http://apteka-porno.ru .
новые порно видео http://www.apteka-porno.ru .
порно коллекции бесплатно https://www.porn-library.ru .
коллекция порно видео коллекция порно видео .
порно видео смотреть порно видео смотреть .
порно коллекции бесплатно https://www.porn-library.ru .
новые порно видео apteka-porno.ru .
новые порно видео http://www.apteka-porno.ru .
Привет!
Заказать документ о получении высшего образования вы можете у нас.
diplomyx.com/kupit-diplom-vracha
Успешной учебы!
Привет, друзья!
Где купить диплом по необходимой специальности?
Купить диплом о высшем образовании.
ya.5bb.ru/viewtopic.php?id=19918#p60304
Привет!
Где заказать диплом по нужной специальности?
Заказать диплом о высшем образовании.
dinsta-gram.com/read-blog/4702
paxlovid cost without insurance: paxlovid price – paxlovid for sale
смотреть классное порево смотреть классное порево .
порно видео порно видео .
doxycycline 300 mg cost: doxycycline 40 mg capsules – generic doxycycline online
http://amoxildelivery.pro/# amoxicillin discount
Добрый день!
Где купить диплом по актуальной специальности?
Приобрести диплом любого ВУЗа.
wiki.wonikrobotics.com/AllegroHandWiki/index.php/Special:AWCforum/post/todo_new_t/id7
порно коллекция порно коллекция .
грузовой подъемник четырехстоечный https://podemniki-gruzovye.ru
порево классный секс http://www.klassny-sex.ru/ .
Добрый день!
Мы можем предложить дипломы любой профессии по разумным ценам.
naya.social/read-blog/81_proverennyj-i-nadezhnyj-internet-magazin-s-shirokim-katalogom-diplomov.html?mode=day
https://doxycyclinedelivery.pro/# drug doxycycline
buy clomid without prescription: can i order clomid pills – where to buy cheap clomid online
Bayern Munich’s https://bayern.jamal-musiala-ar.com young midfielder, Jamal Musiala, has become one of the brightest talents in European football.
Thibaut Courtois https://real-madrid.thibaut-courtois-ar.com was born on May 11, 1992 in Belgium.
Hi there! I could have sworn I’ve visited this site before but after going through a few of the articles I realized it’s new to me. Nonetheless, I’m definitely delighted I discovered it and I’ll be bookmarking it and checking back regularly!
Добрый день!
Мы готовы предложить документы техникумов, расположенных в любом регионе РФ. Можно приобрести качественно напечатанный диплом за любой год, включая документы старого образца СССР. Дипломы и аттестаты выпускаются на бумаге высшего качества. Это позволяет делать настоящие дипломы, не отличимые от оригиналов. Документы будут заверены всеми требуемыми печатями и штампами.
nova-driving-school.mn.co/posts/61837854
https://ciprodelivery.pro/# purchase cipro
https://clomiddelivery.pro/# can you get generic clomid for sale
https://amoxildelivery.pro/# amoxicillin 875 125 mg tab
It’s hard to come by educated people about this topic, but you sound like you know what you’re talking about! Thanks
Привет, друзья!
Приобрести документ о получении высшего образования вы сможете в нашем сервисе.
asxdiplomik.com/kupit-diplom-o-vysshem-obrazovanii
Do you have a spam issue on this blog; I also am a blogger, and I was wondering your situation; many of us have created some nice methods and we are looking to exchange strategies with others, please shoot me an e-mail if interested.
https://tatar.org.ru