javascript - 如果 index.html 不加载任何 javascript,Vue 应用程序如何启动?
问题描述
我读过的关于 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>
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网站。
推荐阅读
- sql - 根据 ID 引用更新另一个表中的值
- mysql - 在 SQL 中进行不同的选择,选择除一个不同的所有“类别”
- elasticsearch - Elasticsearch 查询速度极慢且效率不高
- structure - 项目结构
- javascript - 稍后加载元素,以提高页面速度,但使其对 SEO 可见?
- reactjs - 如何将事件处理程序添加到 SortableElement 的子组件?
- python - 如何将文本表转换为 pandas 数据框?
- android - 边界回调的问题,如何正确使用它?
- android - Kotlin:isNullOrEmpty 与 TextUtils.isEmpty
- vue.js - 使用 VUE 的多个秒表