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

to-zip-webpack-plugin

v1.0.3

Published

A simple and easy-to-use webpack compression plugin that can automatically zip/rar the output.path configured by webpack after packaging, and can customize the compression source, generate compression logs, and automatically generate multiple types of uni

Downloads

3

Readme

to-zip-webpack-plugin

一个简单易用的 webpack 压缩插件,在打包后可以自动对webpack配置的output.path进行zip/tar压缩,并且可以自定义压缩源、生成压缩日志、自动生成多种类型的唯一文件名

NPM : https://www.npmjs.com/package/to-zip-webpack-plugin

npm i --save-dev to-zip-webpack-plugin

webpack.config.js

const ToZipWebpackPlugin = require('to-zip-webpack-plugin')
module.exports = {
  entry: 'index.js',
  output: {
    path: __dirname + '/dist',
    filename: 'index_bundle.js'
  },
  plugins: [
    new ToZipWebpackPlugin()
  ]
}

支持零配置,默认对webpack打包完成后output.path进行压缩到path同级目录。

同时支持多个可选参数:

    plugins: [
      new ToZipWebpackPlugin({
        deleteFileList: ["./last.zip", "/dist"], //在压缩完成后删除deleteFileList中的文件夹或目录
        format: "zip", //要压缩的格式 支持zip、tar  默认zip
        fileName: "test", //压缩文件名 默认自动生成时间字符串文件名
        defaultFileName: "uuid", //当不设置fileName 时会自动生成文件名,支持uuid  timestamp time
        archive: {
          //自定义压缩源/目标,设置archive时以下参数必填
          source: __dirname + "/other.config-test.js", //要压缩的文件/目录的路径
          targetDir: __dirname, //压缩文件最终的输出目录
          fileName: "bundlejs", //压缩的文件名
        },
        log: true, //是否记录压缩操作日志到当前目录ToZipWebpackPlugin.log
        zlibLevel: 9, //设置压缩等级、默认9
      }),
    ]

打包后看到ToZipWebpackPlugin.log以下输出说明压缩完成:

[2022-05-14T20:05:52.028] [INFO] ToZipWebpackPlugin - Compression finish ! -  /Users/wsp/vuetest/bundlejs.zip  Size: 0.00M
[2022-05-14T20:05:52.171] [INFO] ToZipWebpackPlugin - Compression finish ! -  /Users/wsp/vuetest/497bfd78-7da6-45ab-97b3-0d126981bfcd.zip  Size: 0.21M

设置defaultFileName会自动生成唯一的压缩文件名支持uuid、时间戳、时间字符串 格式yyyymmddhhMMss:

    plugins: [
      new ToZipWebpackPlugin({
        format: "tar", //要压缩的格式 支持zip、tar
        defaultFileName: "timestamp", //当不设置fileName 时会自动生成文件名,支持uuid  timestamp time
        zlibLevel: 3, //设置压缩等级
        log:true
      }),
    ],

ToZipWebpackPlugin.log

defaultFileName: "timestamp"

[2022-05-14T20:44:56.946] [INFO] ToZipWebpackPlugin - Compression finish ! -  /Users/wsp/vuetest/1652532292483.tar  Size: 0.68M

defaultFileName: "time"

[2022-05-14T20:45:47.496] [INFO] ToZipWebpackPlugin - Compression finish ! -  /Users/wsp/vuetest/20220514204542.tar  Size: 0.68M

内部压缩操作发生在webpackcompiler引擎afterEmit钩子,hook详情:https://webpack.docschina.org/api/compiler-hooks/#afteremit