6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Vue.js で package.json の version をページに埋め込む

Posted at

埋め込む

こんな感じで取り出せるようです。


  data () {
    return {
      version: require('../package.json').version
    }
  },

あとは build するたびに、package.jsonのversionを上げれば良さそうです。

とりあえずマイナバージョンだけ管理できればよさそう、且つ、どうせ捨てるコード、と思って、
雑に shell で書きましたが、もっといい方法あるのでしょうか
npm run build が走るたびに勝手に上がる、のような)。

majorversion=$(cat package.json | grep -o "\"version\".*[0-9.]*" | grep -o "[0-9]*" | head -n 1 | tail -n 1)
minorversion=$(cat package.json | grep -o "\"version\".*[0-9.]*" | grep -o "[0-9]*" | head -n 2 | tail -n 1)
subminorversion=$(cat package.json | grep -o "\"version\".*[0-9.]*" | grep -o "[0-9]*" | head -n 3 | tail -n 1)
subminorversion=$(($subminorversion+1))
version="$majorversion.$minorversion.$subminorversion"
sed -i -e "s|\(\"version\": \"\)\([0-9.]*\)\(\".*\)|\1$version\3|g" package.json
6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?