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

bundlesize-webpack-plugin

v1.0.1

Published

是一个自定义的 webpack 插件,主要作用是检查 webpack 构建输出的最终 bundle 文件的大小,并与设定的大小限制进行比较,然后根据比较结果输出相应的信息

Downloads

4

Readme

编写 webpack 插件

/*_ 推荐文章 _/ https://segmentfault.com/a/1190000022056204#item-1

步骤

源码相关

  • npm init --yes 初始化一个 package.json 文件,用来管理 npm 的所有依赖
  • npm install webpack webpack-cli --save 【 webpack 是 webpack 的核心模块 webpack-cli 是 Webpack 的 CLI 程序,用来在命令行中调用 webpack】
  • npx webpack --version
  • npx webpack 进行打包构建 打包之后的文件在 dist 文件夹下

配置相关

在 webpack.config.js 中进行相关的配置

webpack 相关概念

  • mode : 选择打包的环境
  • entry:入口
  • output:出口
  • loader: 用于对模块的源代码进行转换
  • plugin: 用于解决 loader 无法解决的事情 -- webpack 插件是一个具有 apply 方法的 JavaScript 对象。apply 方法会被 webpack compiler 调用,并且在 整个 编译生命周期都可以访问 compiler 对象。

说明

是一个自定义的 webpack 插件,主要作用是检查 webpack 构建输出的最终 bundle 文件的大小,并与设定的大小限制进行比较,然后根据比较结果输出相应的信息

  • 如果文件大小小于 sizeLimit,则输出安全信息。
  • 如果文件大小等于 sizeLimit,则输出警告信息。
  • 如果文件大小超过 sizeLimit,则输出错误信息。 -- 这个插件可以用于确保生成的 bundle 文件不会过大,从而影响网页加载性能。通过在构建过程中集成这种检查,开发者可以及时发现并优化打包后的资源文件,保持应用的轻量化和高性能。

包的使用

安装

npm install bundlesize-webpack-plugin

导入

const bundlesizeWebpackPlugin = require('bundlesize-webpack-plugin')

输出

Safe:Bundle-Size 1.28 KB
SIZE LIMIT: 3
asset build.js 1.28 KiB [emitted] (name: main)
./src/index.js 27 bytes [built] [code generated]
webpack 5.92.1 compiled successfully in 889 ms