I\'d like to inject a build number and version information to my project as it\'s built with webpack. For example, so that my code can do something like:
var bui
I would do more simpler, just use npm version patch
(npm-version) (no plugin required)
package.json (Example path version before building)
{
"version": "1.0.0",
"scripts": {
"build": "npm version patch && node build/build.js"
}
}
So when you run npm run build
this will patch the version (1.0.0
to 1.0.1
in your package.json)
Bonus: You can also add this to your config (example config/prod.env.js
)
'use strict'
const pkg = require('./package.json')
module.exports = {
NODE_ENV: '"production"',
VERSION: pkg.version
}
Then you can use process.env.VERSION
anywhere in your our JS
Updated: Or just use process.env.npm_package_version
without required to include package.json