我读过的有关 Vue 的资源都没有尝试解释 Vue 应用程序是如何启动的。涉及三个文件:public/index.html、src/main.js、src/App.vue。使用 vue cli 4.1.1 创建的脚手架包含此 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">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title>sample-vue-project</title>
</head>
<body>
<noscript>
<strong>We're sorry but sample-vue-project doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
main.js 文件创建 Vue 应用程序本身,但 index.html 不会加载 main.js。如果我双击index.html,我会得到一个空白页面,因此必须有其他东西介入才能启动应用程序。index.html 中的注释说文件将被自动注入,但是注入是什么呢?
Vue 启动过程是否记录在某处?
当您在本地开发时,Vue Cli 会处理注入,因为您的运行命令类似于npm run serve默认配置。
当您开始将代码投入生产时,您最终将运行一个不同的命令,npm run build该命令将创建一组新文件,其中 index.html 文件将包含引用所有 javascript 代码的脚本标记。在底层,它使用 webpack 来完成所有资产链接。
有关更多详细信息,请参阅Vue Cli网站。
| 归档时间: |
|
| 查看次数: |
5168 次 |
| 最近记录: |