npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

build-statistics-webpack-plugin

v1.0.3

Published

build statistics

Downloads

936

Readme

build-statistics-webpack-plugin

BuildStatisticsPlugin 是一个webpack插件,用于上报webpack各阶段的耗时信息。

1. 用法

webpack.config.js中配置,

const BuildStatisticsPlugin = require('build-statistics-webpack-plugin');
...
module.exports = {
    ...,
    plugins: [
        ...,
        new BuildStatisticsPlugin({
            path: ...,  // 一个文件的绝对地址
        }),
    ],
};

2. 文件内容

BuildStatisticsPlugin会自动向指定的path中写入统计数据。
webpack buildwebpack watch,以及webpack-dev-server的场景中,都会写入文件,
值得注意的是,当监测到文件变更时,不写文件。

文件内容是一个JSON,

{
    hash: ...,
    stages: [
        {
            stage, 
            startTime, 
            endTime, 
            elpase
        },
        ...,
    ]
}

(1)hash hash为webpack自带的stats中的hash字段。

(2)stages stages是一个数组,其中保存了webpack构建过程中,各阶段的耗时信息。

stage表示阶段名:

| stage | description | begin | end | | --- | --- | --- | --- | | start | 准备阶段 | compiler.hooks.compile | compiler.hooks.compilation | | load | 载入文件 | compiler.hooks.compilation | compilation.hooks.finishModules | | assets | 代码生成 | compilation.hooks.finishModules | compilation.hooks.additionalAssets | | uglify | 压缩 | compilation.hooks.additionalAssets | compilation.hooks.afterOptimizeChunkAssets | | emit | 写文件 | compilation.hooks.afterOptimizeChunkAssets | compiler.hooks.done |

startTimeendTime为该阶段的开始和结束时间,
elapse为该阶段耗时。

3. 日志

插件内部使用了debug,用来记录trace日志和error日志,
命令行中传入以下前置参数,可以获取完整日志。例如,

$ DEBUG=build-statistics-webpack-plugin* webpack

结果如下,

build-statistics-webpack-plugin:trace 开始compile +0ms
build-statistics-webpack-plugin:trace 创建一个新的compilation +10ms
build-statistics-webpack-plugin:trace 开始载入文件 +0ms
build-statistics-webpack-plugin:trace 载入文件结束 +523ms
build-statistics-webpack-plugin:trace 生成目标文件名和文件内容 +38ms
build-statistics-webpack-plugin:trace 对文件内容进行压缩 +11ms
build-statistics-webpack-plugin:trace 完成 +4ms
build-statistics-webpack-plugin:trace 各事件发生的时刻:[{"event":"compiler.compile","timestamp":1542187628407},{"event":"compiler.compilation","timestamp":1542187628414},{"event":"compilation.finishModules","timestamp":1542187628937},{"event":"compilation.additionalAssets","timestamp":1542187628975},{"event":"compilation.afterOptimizeChunkAssets","timestamp":1542187628986},{"event":"compiler.done","timestamp":1542187628990}] +1ms
build-statistics-webpack-plugin:trace 各阶段耗时:[{"stage":"start","startTime":1542187628407,"endTime":1542187628414,"elapse":7},{"stage":"load","startTime":1542187628414,"endTime":1542187628937,"elapse":523},{"stage":"assets","startTime":1542187628937,"endTime":1542187628975,"elapse":38},{"stage":"uglify","startTime":1542187628975,"endTime":1542187628986,"elapse":11},{"stage":"emit","startTime":1542187628986,"endTime":1542187628990,"elapse":4}] +0ms
build-statistics-webpack-plugin:trace hash:16555666ef09ced98421 +12ms
build-statistics-webpack-plugin:trace 准备写文件 +0ms
build-statistics-webpack-plugin:trace 写入文件:***/1542187627983.json