// index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <link rel="icon" type="image/svg+xml" href="/vite.svg" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>堆代码 duidaima.com</title> </head> <body> <div id="app"></div> <script type="module" src="/src/main.js"></script> </body> </html> // /src/main.js import { createApp } from 'vue' import App from './App.vue' createApp(App).mount('#app'); // src/App.vue <template> <h1>Hello</h1> </template>在浏览器中打开页面后,会发现浏览器对入口文件发起了请求:
const _sfc_main = { name: 'App' } // vue 提供的一些API,用于生成block、虚拟DOM import { openBlock as _openBlock, createElementBlock as _createElementBlock } from "/node_modules/.vite/vue.js?v=b618a526" function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { return (_openBlock(), _createElementBlock("h1", null, "App")) } // 组件的render方法 _sfc_main.render = _sfc_render; export default _sfc_main;
总结:
当用户访问 vite 提供的开发服务器时,对于浏览器不能直接识别的文件,服务器的一些中间件会将此类文件转换成浏览器认识的文件,从而保证正常访问。