前端相关技巧

分析 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

评论栏