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
There is a plugin to auto inject version from package.json
.
It can inject it into HTML, CSS, JS as a comment, but also as a value by special tag webpack-auto-inject-version.
How to:
First of all, you have to add it to your project:
npm i webpack-auto-inject-version
Then you need to set up your webpack config:
var WebpackAutoInject = require('webpack-auto-inject-version');
module.exports = {
plugins: [
new WebpackAutoInject()
]
}
As you want to inject it into javascript, you should add a tag inside your javascript file ( which will be changed to version during the webpack compilation )
var version = '[AIV]{version}[/AIV]';
console.log(version);
Auto increasing:
You can set it up to auto increase the version directly from webpack by:
webpack --other-webpack-settings --major
webpack --other-webpack-settings -- minor
webpack --other-webpack-settings --patch
Where --other-webpack-settings
is equal to your custom line args.
Simplifying - you need to att --major
, --minor
or --patch
whenever you want to auto increase a version.