先逐级递归识别依赖,构建依赖图谱
重点: 这里需要递归识别依赖,构建依赖图谱。图谱对象就是类似下面这种
{
'./app.js': {
dependencies: {
'./test1.js': './test1.js'
},
code: '"use strict";nnvar _test = _interopRequireDefault(require("./test1.js"));nnfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }nnconsole.log(test 1);'
},
'./test1.js': {
dependencies: {
'./test2.js': './test2.js'
},
code: '"use strict";nnvar _test = _interopRequireDefault(require("./test2.js"));nnfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }nnconsole.log('th is is test1.js ', _test["default"]);'
},
'./test2.js': {
dependencies: {},
code: '"use strict";nnObject.defineProperty(exports, "__esModule", {n value: truen});nexports["default"] = void 0;nnfunction test2() {n console.log('this is test2 ');n}nnvar _default = tes t2;nexports["default"] = _default;'
}
}
如:
<script type="module" src="/src/main.js"></script>
http://localhost:3000/src/main.js请求main.js文件:
// /src/main.js:
import { createApp } from 'vue'
import App from './App.vue'
createApp(App).mount('#app')
GET http://localhost:3000/@modules/vue.js
GET http://localhost:3000/src/App.vue
Vite
的主要功能就是通过劫持浏览器的这些请求,并在后端进行相应的处理将项目中使用的文件通过简单的分解与整合,然后再返回给浏览器,vite整个过程中没有对文件进行打包编译,所以其运行速度比原始的webpack
开发编译速度快出许多!esbuild
预构建依赖。Esbuild 使用 Go 编写,并且比以 Node.js
编写的打包器预构建依赖快 10-100 倍。Vite 只需要精确地使已编辑的模块与其最近的 HMR 边界之间的链失效(大多数时候只需要模块本身),使 HMR 更新始终快速,无论应用的大小
。M1
芯片Mac
,都说好,但是一开始买的人不多,担心生态问题,后面都说真香vite
即将大放异彩!