简体   繁体   English

我可以使用 webpack 加速我的 React 和 Type 项目吗?

[英]Can i speed up my React and Type project using webpack?

I have a project and it's huge.我有一个项目,而且很大。 And when I write npm start it takes 6 to 8 minutes to load.当我写 npm 开始时,加载需要 6 到 8 分钟。 Is it possible to make it so that you can first quickly load the sign in page, and only then everything else?是否有可能让您首先快速加载登录页面,然后才能加载其他所有内容?

To answer this question correctly, would need some specifics of the project like要正确回答这个问题,需要项目的一些细节,比如

  • How is it structured?它的结构如何?
  • Is it decoupled enough?是否足够解耦?
  • Can components work separately from each other?组件可以彼此分开工作吗?

Nevertheless, if its only a signup page, I assume there will be a simple input form and a network call for authorization.尽管如此,如果它只是一个注册页面,我假设会有一个简单的输入表单和一个网络调用授权。

To make this work, extract the component responsible for authentication into a single component, and if the component has some extra dependencies, try to lazy load them with lazy imports为了使这个工作,将负责身份验证的组件提取到单个组件中,如果该组件有一些额外的依赖项,请尝试使用延迟导入来延迟加载它们

import { lazy } from 'react';

const later_package = lazy(() => { import './later_dependency'})

Note: the above lazy import only works with default imports.注意:上述惰性导入仅适用于默认导入。

  • more about code splitting here更多关于代码拆分的信息

for webpack do some bundle analysis for the bundle check if the bundle dependencies are what are slowing down the build.对于 webpack 做一些捆绑包分析,检查捆绑包依赖项是否会减慢构建速度。 If not, split the entry points.如果没有,则拆分入口点。 More about Webpack code-splitting here更多关于 Webpack 代码拆分 在这里

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

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