0.9.10 • Published 10 months ago

wind-plugin-tar v0.9.10

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

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 描述说明
disableBooleanundefineddisable the plugin是否禁用此插件vite环境可自动识别,无须配置其他环境,若未配置此选项,则当NODE_ENVproduction时启用,否则不启用。
bundlerStringvite默认为viteplugin environment插件环境使用插件默认导出的tar方法,需要配置此参数可选值:viterollupwebpack
dirStringget from the bundler config自动从vite中获取输出目录配置directory to tar打包压缩目录
nameStirng{name}{stamp}{project}v{version}{mode}.tar.gzname of output file打包压缩文件名name是从package.json中获取的名称stamp是时间戳,为yyyyMMddHH格式project是从package.json里对应字段获取的相关项目信息,没有则为空version是从package.json中获取的版本号mode是打包模式,默认从vite中获取,可通过设置mode参数覆盖
modeStirngget from the bundler config(if supported)自动从编译配置中获取打包模式(如果支持设置mode的话)build mode编译模式
shellStirngwindows: 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 待办

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

Support 支持

  • 支持vite打包工具
  • 支持自定义打包模式
0.9.10

10 months ago

0.9.1

11 months ago

0.8.25

11 months ago