LoginSignup
0

More than 3 years have passed since last update.

Vue.jsのプロジェクト内(Vue-Cli version2系)でpackage.jsonのバージョン番号を参照したい

Posted at

Vue-CLI2で作成したVueプロジェクトでpackage.json内にあるバージョン番号を使用したかったので調べました。
Vue-CLI3はここの記事の方法だとだめなようです。その場合はこちらのQAを参照してください。

vue.config.js
const webpack = require('webpack');

module.exports = {
    configureWebpack: {
        plugins: [
            new webpack.DefinePlugin({
                'process.env': {
                    PROJECT_VERSION: '"' + (require('./package.json')).version + '"'
                }
            })
        ]
    },
}

使用する側

App.vue
mounted() {
    console.log(`Version=${process.env.PROJECT_VERSION}`);
}

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
0