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

wind-plugin-tar

v0.9.10

Published

Tar the result files after building

Downloads

8

Readme

wind-plugin-tar

Tar the result files after building.
编译完成后自动进行tar打包压缩,最终得到xxx.tar.gz文件。

Introduction 原理说明

通过调用shell命令 tar -czf xxx.tar.gz dist,将编译后的dist文件打包成xxx.tar.gz文件。

Install 安装

# pnpm
pnpm add wind-plugin-tar -D

# yarn
yarn add wind-plugin-tar -D

# npm
npm install wind-plugin-tar -D

Options 配置

| Parameter 参数 | Types 类型 | Default 默认值 | Description 描述说明 | ---------- | --------------------- | --------------------------- | ------------ |disable | Boolean | undefined | disable the plugin是否禁用此插件vite环境可自动识别,无须配置其他环境,若未配置此选项,则当NODE_ENVproduction时启用,否则不启用。 |bundler | String | vite默认为vite | plugin environment插件环境使用插件默认导出的tar方法,需要配置此参数可选值:viterollupwebpack |dir | String | get from the bundler config自动从vite中获取输出目录配置 | directory to tar打包压缩目录 |name | Stirng | {name}{stamp}{project}v{version}{mode}.tar.gz | name of output file打包压缩文件名name是从package.json中获取的名称stamp是时间戳,为yyyyMMddHH格式project是从package.json里对应字段获取的相关项目信息,没有则为空version是从package.json中获取的版本号mode是打包模式,默认从vite中获取,可通过设置mode参数覆盖 |mode | Stirng | get from the bundler config(if supported)自动从编译配置中获取打包模式(如果支持设置mode的话) | build mode编译模式 |shell | Stirng | windows: pwsh or powershell, others: nodejs defaultwindows系统将自动使用pwsh或者powershell,其他系统为nodejs默认设置 | the shell to use for the tar commandtar命令运行的shell环境建议在.env环境变量文件中配置,插件将自动从process.env中获取TAR_SHELL结尾的环境变量作为shell环境

Usage 使用

  • vite

      // vite config
      import { defineConfig } from 'vite'
      import { tarInVite } from "wind-plugin-tar";
    
      export default defineConfig({
          plugins: [
              tarInVite() // use default options 使用默认配置
          ]
      })
    
      /* 或者下列指定bundler方式 */
        
      import { defineConfig } from 'vite'
      import tar from "wind-plugin-tar";
    
      export default defineConfig({
          plugins: [
              tar({ bundler: "vite" }) // need to specify the bundler('vite' by default) 需要指定bundler类型(默认是vite)
          ]
      })
  • rollup

      // rollup config
      import { tarInRollup } from "wind-plugin-tar";
    
      export default {
          plugins: [
              tarInRollup() // use default options 使用默认配置
          ]
      }
    
      /* 或者下列指定bundler方式 */
        
      import tar from "wind-plugin-tar";
    
      export default {
          plugins: [
              tar({ bundler: "rollup" }) // need to specify the bundler  需要指定bundler类型
          ]
      }
  • webpack

    • webpack 示例
      // webpack config
      import { tarInWebpack } from "wind-plugin-tar";
    
      module.exports = {
          plugins: [
              tarInWebpack() // use default options 使用默认配置
          ]
      }
    
      /* 或者下列指定bundler方式 */
        
      import tar from "wind-plugin-tar";
    
      module.exports = {
          plugins: [
              tar({ bundler: "webpack" }) // need to specify the bundler  需要指定bundler类型
          ]
      }
    • vue-cli 示例
      // vue-cli config
      import { tarInWebpack } from "wind-plugin-tar";
    
      module.exports = {
          // ...
          chainWebpack: (config) => {
              config.plugin("wind-plugin-tar").use(tarInWebpack()); // use default options 使用默认配置
          },
          // ...
      }
    
      /* 或者下列指定bundler方式 */
        
      import tar from "wind-plugin-tar";
    
      module.exports = {
          // ...
          chainWebpack: (config) => {
              config.plugin("wind-plugin-tar").use(tar({ bundler: "webpack" })); // need to specify the bundler  需要指定bundler类型
          },
          // ...
      }

Tips 小技巧

当项目成功编译后可见如下输出日志:

  • 打包压缩: tar -czf vt2024083115v0.0.0production.tar.gz dist
  • 开始时间: 2024/8/31 15:24:11 -- 结束时间: 2024/8/31 15:24:11
  • 解压命令: tar -xzf vt2024083115v0.0.0production.tar.gz -C . --strip-components=0
    # 解压命令小技巧:
    tar -xzf xxx.tar.gz -C . --strip-components=0
    # -C表示解压目录,其中的"."表示当前目录
    # --strip-components表示解压后提取的tar包的目录层级,=1可以忽略根目录(如dist目录),直接得到其子文件夹和文件

TODO 待办

  • [ ] 支持其他打包工具
    • [x] webpack
    • [x] rollup
    • [ ] esbuild
  • [ ] 增加前置/后置命令

Support 支持

  • [x] 支持vite打包工具
  • [x] 支持自定义打包模式