简体   繁体   English

Laravel / Vue - App.js import 和 require 之间的区别

[英]Laravel / Vue - App.js difference between import and require

Are there any significant difference between these two syntax?这两种语法之间有什么显着区别吗?

Vue.component('base-table', () => import('./components/BaseTable.vue'))
Vue.component('base-table', require('./components/BaseTable.vue').default);

Is one or the other affects the loading performance of an application?一个或另一个会影响应用程序的加载性能吗?

From the Webpack docs:来自 Webpack 文档:

require要求

Synchronously retrieve the exports from another module.从另一个模块同步检索导出。 The compiler will ensure that the dependency is available in the output bundle编译器将确保依赖项在输出包中可用

import()进口()

Dynamically load modules.动态加载模块。 Calls to import() are treated as split points, meaning the requested module and its children are split out into a separate chunk.对 import() 的调用被视为分割点,这意味着请求的模块及其子模块被分割成一个单独的块。

Simply 1st puts your BaseTable.vue component into separate JS bundle (file) which will be requested by a browser at the moment component is rendered 1st time.简单地 1st 将您的BaseTable.vue组件放入单独的 JS 包(文件)中,浏览器将在第一次呈现组件时请求该包。 Good for components/parts of app which are not needed immediately (per-route code splitting) or only for some users (admins for example).适用于不需要立即使用(按路由代码拆分)或仅适用于某些用户(例如管理员)的应用程序组件/部分。 Your base bundle size is smaller and thus parsed faster by the browser -> better initial loading performance...您的基本包大小更小,因此浏览器解析速度更快 - > 更好的初始加载性能...

Declaimer: Commenting from Vue/Webpack POV.声明:来自 Vue/Webpack POV 的评论。 I know nothing about Laravel except it's PHP thing...我对 Laravel 一无所知,除了它是 PHP 的东西......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM