在 vite
项目中,index.html
通常是整个应用的入口文件。
vite
利用了浏览器原生ES模块导入的特性,因此可以直接在 index.html
中通过 <script type="module">
标签引入 JavaScript模块,例如:
1<!DOCTYPE html>
2<html lang="en">
3 <head>
4 <meta charset="UTF-8">
5 <link rel="icon" href="/favicon.ico">
6 <meta name="viewport" content="width=device-width, initial-scale=1.0">
7 <title>Hello Vue3</title>
8 </head>
9 <body>
10 <div id="app"></div>
11 <script type="module" src="/src/main.ts"></script>
12 </body>
13</html>
在这个例子中,/src/main.ts
就是项目的主要 JavaScript
文件,它被作为模块从 index.html
中导入。