前端相关技巧

公开 · 所有人可见

分析 Bundle (包) 大小

Source map explorer 使用 source maps 分析 JavaScript 包。 这有助于你了解代码膨胀的来源。

要将 Source map explorer 添加到 Create React App 项目,请按照下列步骤操作:

npm install --save source-map-explorer
或者你可以使用 yarn:

yarn add source-map-explorer

然后在 package.json 中,将以下行添加到 scripts 中:

   "scripts": {
+    "analyze": "source-map-explorer build/static/js/main.*",
     "start": "react-scripts start",
     "build": "react-scripts build",
     "test": "react-scripts test",
     }

然后分析 bundle(包) 运行生产构建然后运行分析脚本。

npm run build
npm run analyze

评论栏

分享你的想法,或参与下面的讨论。

参与讨论

支持 Markdown、代码和图片

撰写评论

友善交流,让讨论更有价值。

更多留言

加载中…