博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
next. js_如何分析Next.js应用程序捆绑包
阅读量:2502 次
发布时间:2019-05-11

本文共 1711 字,大约阅读时间需要 5 分钟。

next. js

Next provides us a way to analyze the code bundles that are generated.

Next为我们提供了一种分析生成的代码束的方法。

Open the package.json file of the app and in the scripts section add those 3 new commands:

打开应用程序的package.json文件,然后在脚本部分中添加这3个新命令:

"analyze": "cross-env ANALYZE=true next build","analyze:server": "cross-env BUNDLE_ANALYZE=server next build","analyze:browser": "cross-env BUNDLE_ANALYZE=browser next build"

Like this:

像这样:

{  "name": "firstproject",  "version": "1.0.0",  "description": "",  "main": "index.js",  "scripts": {    "dev": "next",    "build": "next build",    "start": "next start",    "analyze": "cross-env ANALYZE=true next build",    "analyze:server": "cross-env BUNDLE_ANALYZE=server next build",    "analyze:browser": "cross-env BUNDLE_ANALYZE=browser next build"  },  "keywords": [],  "author": "",  "license": "ISC",  "dependencies": {    "next": "^9.1.2",    "react": "^16.11.0",    "react-dom": "^16.11.0"  }}

then install those 2 packages:

然后安装这两个软件包:

npm install --dev cross-env @next/bundle-analyzer

Create a next.config.js file in the project root, with this content:

在项目根目录中创建一个next.config.js文件,内容如下:

const withBundleAnalyzer = require('@next/bundle-analyzer')({  enabled: process.env.ANALYZE === 'true'})module.exports = withBundleAnalyzer({})

Now run the command

现在运行命令

npm run analyze

This should open 2 pages in the browser. One for the client bundles, and one for the server bundles:

这将在浏览器中打开2个页面。 一种用于客户端捆绑,另一种用于服务器捆绑:

This is incredibly useful. You can inspect what’s taking the most space in the bundles, and you can also use the sidebar to exclude bundles, for an easier visualization of the smaller ones:

这是非常有用的。 您可以检查束中占用最多空间的空间,还可以使用边栏排除束,以更轻松地可视化较小的束:

翻译自:

next. js

转载地址:http://naqgb.baihongyu.com/

你可能感兴趣的文章
Sliverlight实例之 绘制扇形和环形图
查看>>
Visual Studio 2012使用水晶报表Crystal Report
查看>>
你不知道的 页面编码,浏览器选择编码,get,post各种乱码由来
查看>>
SQLSERVER PRINT语句的换行
查看>>
Windows 8.1 应用开发 – 触控操作
查看>>
PowerDesigner创建物理模型
查看>>
使用Git、Git GUI和TortoiseGit
查看>>
vue---canvas实现二维码和图片合成的海报
查看>>
检查项目里是否有IDFA的方法
查看>>
64位系统使用Access 数据库文件的彻底解决方法
查看>>
注释,字符串
查看>>
性能瓶颈
查看>>
cmd 导入数据库
查看>>
Makefile书写注意事项--个人择记(一)
查看>>
文件转码重写到其他文件
查看>>
场景3 Data Management
查看>>
Dubbo入门---搭建一个最简单的Demo框架(转)
查看>>
树结构练习——排序二叉树的中序遍历
查看>>
AC自动机模板
查看>>
python 基本语法
查看>>