Code Monkey home page Code Monkey logo

vite's Introduction

什么是 Vite?

github:https://github.com/vitejs/vite

特点:

  • 1.快速的冷启动
    • 1.1 冷启动 冷启动的时候,应用启动的时候,后台没有该应用的进行,系统会创建一个新的进程,分配给应用。
    • 1.2 热启动 热启动应用的时候,后台已经有了该应用的进程,即使推出应用,但是后台依然存在
  • 2.即时的模块热更新
  • 3.真正的按需编译

vite与webpack 目录结构对比

wdhanJ.png

文件异同点

  • 1.index.html
<script type="module" src="/src/main.js"></script>

那这个是什么呢?请看下边

因为浏览器会识别type='module'的script元素,浏览器会把它当作是ES模块,从而使用HTTP请求获取模块内容

  • 小知识点: ESM 天生就是按需加载的,只有 import 的时候才会去按需加载
<script type="module">
  import { createApp } from './main.js‘;
  createApp();
</script>

弊端:

每个改动,浏览器通过本机<script module>支持对其解析,从而为每个导入都会发出一个HTTP请求.拦截浏览器对模块的请求并返回处理后的结果 wd47I1.png

引发的问题?Vite是如何做到使用HTTP请求拿到模块?

vite会启动一个web server来代理这些模块,其里边就是借助koa启动了一个服务

环境变量

注意:只有带前缀的变量才对VITE_您的代码公开。例如VITE_SOME_KEY=123将暴露为

参考链接

1.Es-import 2.有了 vite,还需要 webpack 么?

vite's People

Contributors

jack-rainbow avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.