javascript - Next.js - bundle 大小太大 (~3MB)

标签 javascript reactjs webpack next.js

我想问一下是否有任何方法可以瘦身我的 Next.JS 包。 尤其是节点模块 - 这会导致浏览器加载大量 MB,从而减慢初始浏览速度。

分析如下:

Next.JS bundle stats analyzer

每当您询问更多信息时,我都欢迎提供更多信息。

最佳答案

看起来您正在使用 webpack,这里有一些需要尝试的事情:

<强> Code Splitting

Code splitting is one of the most compelling features of webpack. This feature allows you to split your code into various bundles which can then be loaded on demand or in parallel. It can be used to achieve smaller bundles and control resource load prioritization which, if used correctly, can have a major impact on load time.

<强> Tree Shaking

Tree shaking is a term commonly used in the JavaScript context for dead-code elimination. It relies on the static structure of ES2015 module syntax, i.e. import and export. The name and concept have been popularized by the ES2015 module bundler rollup.

关于javascript - Next.js - bundle 大小太大 (~3MB),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50501059/

相关文章:

angular - Ionic 3 中的 Algolia Instantsearch.js

javascript - 如何通过Webpack的import语句将CSS提取到Critical.css样式表中?

javascript - 无法在 webpack 配置中使用 ES6 导入

javascript - jQuery:记录数组中元素的变化并通过索引检查它的变化

javascript - Slick Init - slickPause 未定义

javascript - 错误 : The Content-Range header is missing in the HTTP Response

javascript - react 路由器页面无法刷新

javascript - 使用 Javascript 或 jQuery 动态更改 CSS

javascript - 正则表达式提取 img src javascript

reactjs - 对 Enzyme mount() 上下文选项感到困惑