1.1.0 • Published 2 years ago

@wjtools/version-webpack-plugin v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

首先,您需要安装 @wjtools/version-webpack-plugin:

$ yarn add @wjtools/version-webpack-plugin --save-dev

然后将插件添加到您的 webpack 配置。例如:

vue.config.js

configureWebpack: config => {
  if (isProd) {
    // 自动更新 package.json 中的版本号
    const VersionWebpackPlugin = require('@wjtools/version-webpack-plugin')
    config.plugins.push(
      new VersionWebpackPlugin({
        // file: 'package.json', // 指定版本号所在文件,默认:'package.json'
        // version: '1.0.0', // 指定版本号,默认取 file 指定文件中的版本号
        // mode: 'increment', // 更新模式:increment-递增(默认);timestamp-时间戳
      }),
    )
  }
},

每次打包会生成新的递增的版本号,直接导入即可使用,例如:

main.js

import { version } from '../package'

版本号兼容 1.x.xx.xx 等写法