webpack-auto-inject-version/README.md

106 lines
2.5 KiB
Markdown
Raw Normal View History

2016-10-21 19:04:52 +11:00
# Auto inject version - Webpack plugin
2017-04-11 09:11:09 +10:00
Adds version from package.json into every single file as top comment block.
2016-10-20 17:58:19 +11:00
2017-04-13 07:47:11 +10:00
# Install
2017-04-11 09:11:09 +10:00
```console
$ npm install webpack-auto-inject-version --save-dev
```
2017-04-13 07:47:11 +10:00
# Table of Contents
[What it does](#What-it-does)
[How to use](#How-to-use)
[Available options](#Available-options)
[Examples of the plugin outputs](#Examples-of-the-plugin-outputs)
# What it does
2016-10-21 18:32:35 +11:00
Auto Inject Version (AIV) can:
- inject version from package.json into every bundle file as a comment ( at the top )
2017-04-11 09:11:09 +10:00
- inject version from package.json into any place in your HTML by special tag `[AIV]{version}[/AIV]`
- inject version from package.json into any place in CSS/JS file by special tag `[AIV]{version}[/AIV]`
- auto increase package.json version by --env.major, --env.minor, --env.patch passed into webpack
2016-10-21 18:32:35 +11:00
2016-10-20 17:58:19 +11:00
2016-10-20 19:32:26 +11:00
2017-04-13 07:47:11 +10:00
# How to use
It's easy to set it up, all you need is:
* use WebpackAutoInject in webpack plugins
* pass config as a parameter, or leave it blank as all options are "on" by default.
2016-10-20 19:32:26 +11:00
2017-04-13 07:47:11 +10:00
### Example ( in webpack.conf.js )
```js
var WebpackAutoInject = require('webpack-auto-inject-version');
...
2016-10-20 19:32:26 +11:00
module.exports = {
2017-04-13 07:47:11 +10:00
...
2016-10-20 17:58:19 +11:00
plugins: [
2017-04-11 09:11:09 +10:00
new WebpackAutoInject({
// options
// example:
components: {
AutoIncreaseVersion: false
}
})
2016-10-20 17:58:19 +11:00
]
2016-10-20 19:32:26 +11:00
}
```
2017-04-13 07:47:11 +10:00
# Available options
2016-10-20 19:32:26 +11:00
2017-04-11 09:11:09 +10:00
### components.AutoIncreaseVersion
2016-10-20 19:32:26 +11:00
Auto increase package.json number. <br>
This option requires extra argument to be sent to webpack build. <br>
2016-10-21 18:32:35 +11:00
It happens before anything else to make sure that your new version is injected into your files.<br>
2017-04-11 09:11:09 +10:00
Arguments: --env.major --env.minor --env.patch<br><br>
2016-10-20 19:32:26 +11:00
Example for package.json run type, npm run start => ( 1.2.10 to 2.0.0 )
```json
"version" : "1.2.10",
"scripts": {
2017-04-11 09:11:09 +10:00
"start": "webpack --env.major"
2016-10-20 19:32:26 +11:00
}
```
Default: true
2017-04-11 09:11:09 +10:00
### components.InjectByTag
2016-10-21 18:32:35 +11:00
Inject version number into your file<br>
Version will replace the <{version}> tag.<br>
2016-10-20 19:32:26 +11:00
```html
2017-04-11 09:11:09 +10:00
<span>My awesome project | [AIV]{version}[/AIV]</span>
2016-10-20 19:32:26 +11:00
```
2016-10-21 18:32:35 +11:00
```js
2017-04-11 09:11:09 +10:00
var version = '[AIV]{version}[/AIV]';
2016-10-21 18:32:35 +11:00
```
2016-10-20 19:32:26 +11:00
Default: true
2017-04-11 09:11:09 +10:00
### components.InjectAsComment
This will inject your version as a comment into any css,js,html file.<br>
Default: true
2016-10-20 19:32:26 +11:00
2017-04-13 07:47:11 +10:00
# Examples of the plugin outputs
AIV can inject version number for all your bundle files (css,js,html).<br><br>
```js
// [AIV] Build version: 1.0.10
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
```
<br><br>
Example html:
```html
<!-- [AIV] Build version: 1.0.10 -->
<!DOCTYPE html>
<html lang="en">
```