Git Product home page Git Product logo

webpack-auto-inject-version's Introduction

Auto inject version - Webpack plugin

Adds version from package.json into every single file as top comment block.

Install

$ npm install webpack-auto-inject-version --save-dev

Table of Contents

What it does
How to use
Available options
Output examples How to use with other webpack plugins
Change log

What it does

Auto Inject Version (AIV) can:

  • inject version from package.json into every bundle file as a comment ( at the top )
  • 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

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.

Simple config example ( in webpack.conf.js )

var WebpackAutoInject = require('webpack-auto-inject-version');
...
module.exports = {
    ...
    plugins: [
        new WebpackAutoInject({
            // options
            // example:
            components: {
                AutoIncreaseVersion: false
            }
        })
    ]
}

Full config example ( in webpack.conf.js )

module.exports = {
    ...
    plugins: [
      new WebpackAutoInject({
        // specify the name of the tag in the outputed files eg
        // bundle.js: [SHORT]  Version: 0.13.36 ...
        SHORT: 'CUSTOM',
        SILENT: false,
        PACKAGE_JSON_PATH: './package.json',
        PACKAGE_JSON_INDENT: 4,
        components: {
          AutoIncreaseVersion: true,
          InjectAsComment: true,
          InjectByTag: true
        },
        componentsOptions: {
          AutoIncreaseVersion: {
            runInWatchMode: false // it will increase version with every single build!
          },
          InjectAsComment: {
            tag: 'Version: {version} - {date}',
            dateFormat: 'h:MM:ss TT', // change timezone: `UTC:h:MM:ss` or `GMT:h:MM:ss`
            multiLineCommentType: false, // use `/** */` instead of `//` as comment block
          },
          InjectByTag: {
            fileRegex: /\.+/,
            // regexp to find [AIV] tag inside html, if you tag contains unallowed characters you can adjust the regex
            // but also you can change [AIV] tag to anything you want
            AIVTagRegexp: /(\[AIV])(([a-zA-Z{} ,:;!()_@\-"'\\\/])+)(\[\/AIV])/g,
            dateFormat: 'h:MM:ss TT'
          }
        },
        LOGS_TEXT: {
          AIS_START: 'DEMO AIV started'
        }
      })
    ]
}

Inject by tag example

<body>
  <span>
    [AIV]{version}[/AIV]
  </span>
  <span>
    [AIV]{date}[/AIV]
  </span>
  <span>
    [AIV]{version}_{date}[/AIV]
  </span>
  <span>
    [AIV]V:{version} Date:{date}[/AIV]
  </span>
  <span>
    [AIV]Version {version} , {date}[/AIV]
  </span>
</body>

Available options

components.AutoIncreaseVersion

Auto increase package.json number.
This option requires extra argument to be sent to webpack build.
It happens before anything else to make sure that your new version is injected into your files.
Arguments: --env.major --env.minor --env.patch

Example for package.json run type, npm run start => ( 1.2.10 to 2.0.0 )

 "version" : "1.2.10",
 "scripts": {
    "start": "webpack --env.major"
 }

To enable watch mode:

  plugins: [
    new WebpackAutoInject({
      ...
      components: {
        AutoIncreaseVersion: true,
        ...
      },
      componentsOptions: {
        AutoIncreaseVersion: {
          runInWatchMode: false // it will increase version with every single build!
        }
      }
    })
  ]

Default: true

components.InjectByTag

Inject version number into your file
Version will replace the <{version}> tag.

<span>My awesome project | [AIV]{version}[/AIV]</span>
var version = '[AIV]{version}[/AIV]';

Default: true

components.InjectAsComment

This will inject your version as a comment into any css,js,html file.
You can change what is injected into the file by changing componentsOptions.InjectAsComment.tag. Currently only 2 tags are supported:

  • {version}
  • {date} ( current date ) Example:
  ...
  plugins: [
    ...
    new WebpackAutoInject({
      PACKAGE_JSON_PATH: './package.json',
      components: {
        ...
        InjectAsComment: true
      },
      componentsOptions: {
        ...
        InjectAsComment: {
          tag: 'Build version: {version} - {date}', // default
          dateFormat: 'dddd, mmmm dS, yyyy, h:MM:ss TT', // default
          multiLineCommentType: false, // default
        }
    })
  ]

Default: true

Output-examples

AIV can inject version number for all your bundle files (css,js,html).

// [AIV] Build version: 1.0.10
/******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};



Example html:

<!-- [AIV] Build version: 1.0.10 -->
<!DOCTYPE html>
<html lang="en">

How to use with other webpack plugins

Webpack plugins order matters! Always try to put WebpackAutoInject as a first webpack plugin.

compression-webpack-plugin

  plugins: [
    new WebpackAutoInject(),
    new CompressionPlugin(),
  ]

uglifyjs-webpack-plugin

  plugins: [
    new WebpackAutoInject(),
    new UglifyJsPlugin(),
  ]

webpack.optimize.UglifyJsPlugin

If the order won't be enough, you can always add ignore to the uglifyJsPlugin to prevent stripping out AIV comments eg:

  new webpack.optimize.UglifyJsPlugin({
    ...
    output: {
      // prevent version info to be removed from bundle.js
      comments: /\[AIV\]/,
    },
    ...
  });

Change log

[1.2.2] - 27/10/2018

  • add PACKAGE_JSON_INDENT @trevyn

[1.2.1] - 27/10/2018

  • security updates

[1.2.0] - 27/10/2018

  • inject as comment will no more be a version behind with auto increase version
  • inject as comment can now switched to multiline comment type eg /** */
  • added support for npm log levels eg npm start -s will disable console logs
  • unit tests added inside the demo folder, npm run test

[1.1.0] - 15/03/2018

  • webpack sync apply
  • "name" has been removed as not used anyway, use SHORT instead
  • eslint changes
  • InjectByTag - AIVTagRegexp exposed in config to allow [AIV] tag modifications
  • comma fix in InjectByTag regexp
  • query has on filename has been fixed

[1.0.0] - 25/08/2017

  • Date format can now be specified for InjectAsComment
  • Date format can now be specified for InjectByTag
  • Webpack WATCH support added
  • Root SILENT option added
  • Minor fixes

[0.5.14] - 12/04/2017

  • Remove babel polyfills from webpack build as it was causing issues if babel was already used in project

[0.5.13] - 12/04/2017

  • Tag from InjectAsComment can now be configured by options ( componentsOptions.InjectAsComment.tag )
  • Default tag template for InjectAsComment has change

[0.5.12] - 12/04/2017

  • Fix dependency missing issue
  • Remove export as object with .default as a class

webpack-auto-inject-version's People

Contributors

kidroca avatar radswiat avatar skaronator avatar trevyn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

webpack-auto-inject-version's Issues

argsv.env[arg] fails

Hi,

I'm getting an error on webpack 2.

Package.json:

  • devDependencies:
    • webpack: 2.3.3
    • webpack-auto-inject-version: 0.5.1
  • version: "0.2.0"

Webpack.config.js

  • WebpackAutoInject = require("webpack-auto-inject-version");
  • plugins: [new WebpackAutoInject()]

Log

C:\myfolder\node_modules\webpack-auto-inject-version\dist\WebpackAutoInjectVersion.js:276
return Boolean(argv.env[arg]);
^

TypeError: Cannot read property 'aiv-log-full' of undefined
at isArgv (C:\myfolder\node_modules\node_modules\webpack-auto-inject-version\dist\WebpackAutoInjectVersion.js:276:26)
at Log.getLogLevel (C:\myfolder\node_modules\node_modules\webpack-auto-inject-version\dist\WebpackAutoInjectVersion.js:
170:29)
at new Log (C:\myfolder\node_modules\node_modules\webpack-auto-inject-version\dist\WebpackAutoInjectVersion.js:164:10)
at Object. (C:\myfolder\node_modules\node_modules\webpack-auto-inject-version\dist\WebpackAutoInjectVersion.
js:233:19)
at webpack_require (C:\myfolder\node_modules\node_modules\webpack-auto-inject-version\dist\WebpackAutoInjectVersion
.js:30:30)
at Object. (C:\myfolder\node_modules\node_modules\webpack-auto-inject-version\dist\WebpackAutoInjectVersion.
js:728:12)
at webpack_require (C:\myfolder\node_modules\node_modules\webpack-auto-inject-version\dist\WebpackAutoInjectVersion
.js:30:30)
at C:\myfolder\node_modules\node_modules\webpack-auto-inject-version\dist\WebpackAutoInjectVersion.js:76:18
at C:\myfolder\node_modules\node_modules\webpack-auto-inject-version\dist\WebpackAutoInjectVersion.js:79:10
at webpackUniversalModuleDefinition (C:\myfolder\node_modules\node_modules\webpack-auto-inject-version\dist\WebpackAuto
InjectVersion.js:3:20)

Inject AIV in none bundle files

I have a Library project that outputs individual .js files and a single bundle file (main.js).
Bundle file includes a compiled [AIV] tag.
But the individual compiled files that are compiled does not.

Is there anything I am missing in an option to allow this?
Does the plugin differ from bundled file and compiled files?

Add only to HTML file, not to JS bundle

Right now, the version and build time is injected into the HTML file and the main and vendor JS bundles. Is there a way to customize this? I can think of multiple ways to do it, but not sure which one of it this plugin supports.

  1. Specify that it should be injected only to a specific file (HTML in this case).
  2. Specify what should be injected into each file, probably by file path or file type. (In that case, we can config the plugin to output the version and build time to the HTML file, but only the version number to a JS bundle, and nothing to another bundle, for example).

AIV doesn't output log according to npm's loglevel config.

Hello,

This issue is fairly self-explanatory. If I add any loglevel above info, for example:

loglevel = error

to a project's .npmrc file, AIV still posts 'info' warnings.

Depending on the project, this can contribute to maxbuffer issues.

Document fileRegex setting and NAME, SHORT

I couldn't find any documentation on the fileRegex parameter for InjectByTag. Does this just check the files specified that match the regex for the [AIV] tag?

Also, what are the NAME and SHORT settings for?

Really like this plugin so far, thanks.

Not working with query hash on filename

I have a setup where the chunkhash is added to the file name as a query (e.g. app.js?12345). Unfortunately this breaks the version injection as comment. Injection by tag still seems to work.

My webpack output config:

output: {
      path: path.resolve(__dirname, 'dist'),
      filename: `${assetsSubDirectory}js/[name].js?[chunkhash]`,
      chunkFilename: `${assetsSubDirectory}js/[id].js?[chunkhash]`,
      publicPath: '/', // Public path to 'dist' scope in production
}

Plugin

new WebpackAutoInject({
        SILENT: true,
        components: {
          AutoIncreaseVersion: false,
          InjectAsComment: true,
          InjectByTag: true
        },
        componentsOptions: {
          InjectAsComment: {
            tag: 'Build version: {version} - {date}',
            dateFormat: 'dddd, mmmm d, yyyy, hh:MM:ss'
          }
        }
})

webpack-auto-inject-version doesn't work with webpack 5

Auto inject version started
[webpack-cli] TypeError: this.context.compiler.plugin is not a function
at InjectAsComment.apply (/home/vmazurenko/Documents/projects/qsc/ui/node_modules/webpack-auto-inject-version/dist/WebpackAutoInjectVersion.js:3279:29)
at WebpackAutoInject._executeComponent (/home/vmazurenko/Documents/projects/qsc/ui/node_modules/webpack-auto-inject-version/dist/WebpackAutoInjectVersion.js:2891:12)
at WebpackAutoInject._executeWebpackComponents (/home/vmazurenko/Documents/projects/qsc/ui/node_modules/webpack-auto-inject-version/dist/WebpackAutoInjectVersion.js:2856:12)
at WebpackAutoInject.apply (/home/vmazurenko/Documents/projects/qsc/ui/node_modules/webpack-auto-inject-version/dist/WebpackAutoInjectVersion.js:2829:12)
at createCompiler (/home/vmazurenko/Documents/projects/qsc/ui/node_modules/webpack/lib/webpack.js:74:12)
...

Deprecation Warning with Webpack 4

Hello!

I recently upgraded my app to Webpack 4 and started getting this Deprecation Warning:

DeprecationWarning: Tapable.plugin is deprecated. Use new API on .hooks instead at InjectAsComment.apply (/Users/mthib2/Projects/app/node_modules/webpack-auto-inject-version/dist/WebpackAutoInjectVersion.js:3241:29) at WebpackAutoInject._executeComponent (/Users/mthib2/Projects/app/node_modules/webpack-auto-inject-version/dist/WebpackAutoInjectVersion.js:2879:12) at WebpackAutoInject._executeWebpackComponents (/Users/mthib2/Projects/app/node_modules/webpack-auto-inject-version/dist/WebpackAutoInjectVersion.js:2844:12) at WebpackAutoInject.apply (/Users/mthib2/Projects/app/node_modules/webpack-auto-inject-version/dist/WebpackAutoInjectVersion.js:2817:12) at webpack (/Users/mthib2/Projects/app/node_modules/webpack/lib/webpack.js:37:12) at processOptions (/Users/mthib2/Projects/app/node_modules/webpack-cli/bin/webpack.js:436:16) at yargs.parse (/Users/mthib2/Projects/app/node_modules/webpack-cli/bin/webpack.js:512:3) at Object.parse (/Users/mthib2/Projects/app/node_modules/yargs/yargs.js:552:18) at /Users/mthib2/Projects/app/node_modules/webpack-cli/bin/webpack.js:217:8 at Object.<anonymous> (/Users/mthib2/Projects/app/node_modules/webpack-cli/bin/webpack.js:514:3) at Module._compile (module.js:652:30) at Object.Module._extensions..js (module.js:663:10) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12) at Function.Module._load (module.js:497:3) at Module.require (module.js:596:17) at require (internal/module.js:11:18) at Object.<anonymous> (/Users/mthib2/Projects/app/node_modules/webpack/bin/webpack.js:80:2) at Module._compile (module.js:652:30) at Object.Module._extensions..js (module.js:663:10) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12) at Function.Module._load (module.js:497:3) at Function.Module.runMain (module.js:693:10) at startup (bootstrap_node.js:191:16) at bootstrap_node.js:612:3

Cheers,
Mark

Reset lower # with each increment

Wondering if it makes sense to have this option:
To have the option such that when a minor value is increased the patch value is reset (ie 0). Similarly when a major value is increased the minor and patch values are reset.

source and dist files out of sync

I'm having an issue where this plugin kept modifying indentation in my package.json even after adding PACKAGE_JSON_INDENT: 2 to the configuration. After an inspection of the dist files I noticed that PACKAGE_JSON_INDENT was nowhere to be found.

Turns out that PACKAGE_JSON_INDENT was added in a very recent pr (#39) but the source files were not recompiled.

Note: I didn't recompile dist in this PR, since my build made a lot of other unrelated changes.

comment

So, the new config option was never really released.

My suggestion is to add a "prepublishOnly" script that compiles the files before publishing to npm. This would also mean making git ignore dist/ to avoid confusion like what happened in #39.

My other suggestion is to also, remove PACKAGE_JSON_INDENT. PACKAGE_JSON_INDENT is not necessary since the plugin could just use whatever indentation was already in use.

What do you think? I could submit pr's and address both issues.

Parse Error on Build

When I run a build I get the following errors:

Build Command
"build": "rimraf webpack-dist && webpack --config config/webpack.prod.js --patch --progress --profile --bail",

Index.html

<html>
  <head>
    <base href="/">
    <title>Damage</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="https://cdn.plot.ly/plotly-1.5.0.min.js"></script>
  </head>
  <body>
    <app>Loading Damage Application...Version <{version}></app>
    <span>Version <{version}></span>
  </body>
</html>

Error Message

ERROR in   ModuleBuildError: Module build failed: Error: Parse Error: <{version}></span>
    </body>
  </html>

  - htmlparser.js:236 new HTMLParser
    [MyApp]/[html-minifier]/src/htmlparser.js:236:13

  - htmlminifier.js:957 minify
    [MyApp]/[html-minifier]/src/htmlminifier.js:957:3

  - htmlminifier.js:1310 Object.exports.minify
    [MyApp]/[html-minifier]/src/htmlminifier.js:1310:10

  - index.js:119 Object.module.exports
    [MyApp]/[html-loader]/index.js:119:26

  - NormalModuleMixin.js:315 DependenciesBlock.onModuleBuildFailed
    [MyApp]/[webpack-core]/lib/NormalModuleMixin.js:315:19

  - NormalModuleMixin.js:270 nextLoader
    [MyApp]/[webpack-core]/lib/NormalModuleMixin.js:270:31

  - NormalModuleMixin.js:292
    [MyApp]/[webpack-core]/lib/NormalModuleMixin.js:292:15

  - NormalModuleMixin.js:173 runSyncOrAsync
    [MyApp]/[webpack-core]/lib/NormalModuleMixin.js:173:4

  - NormalModuleMixin.js:290 nextLoader
    [MyApp]/[webpack-core]/lib/NormalModuleMixin.js:290:3

  - NormalModuleMixin.js:259
    [MyApp]/[webpack-core]/lib/NormalModuleMixin.js:259:5

  - CachedInputFileSystem.js:38 Storage.finished
    [MyApp]/[webpack]/[enhanced-resolve]/lib/CachedInputFileSystem.js:38:16

  - graceful-fs.js:78
    [MyApp]/[graceful-fs]/graceful-fs.js:78:16

I'm stuck and any help would be great!

Bug in disabled `InjectAsComment`

Hi!
I think I found a bug in InjectAsComment.

With this config:

// ...
new WebpackAutoInject({
  componentsOptions: {
    InjectByTag: { 
      dateFormat: 'h:MM:ss' 
    }
  }
})

plugin works correctly and replaces [AIV]{date}[/AIV] in html-file with date string.

But when I try to disable comment injecting:

// ...
new WebpackAutoInject({
  components: {
    InjectAsComment: false,
  },
  componentsOptions: {
    InjectByTag: { 
      dateFormat: 'h:MM:ss' 
    }
  }
})

plugin won't replace [AIV]{date}[/AIV] width date anymore.

I'm not sure if this is a bug, but I supposed those features worked independently.

P.S. Thanks for the plugin! :โ€“)

Change bundle name?

Is it possible to change the bundle name by inserting the version?

for example:

module.exports = {
  output: {
    filename: "[name]-[version].min.js",
    path: path.resolve(__dirname, "dist")
  },

How to remove [A/V] in the generated comment

Thanks for this plugin.
Just a little question. Currently, the comment generated and injected looks like this:

// [AIV] Version: 0.0.3-pre-alpha - Wednesday, September 13th, 2017, 11:03:35 PM

I would like to remove the [A/V], but I could not see the options I need to configure to remove this. Would you be kind enough to let me know how? Thanks!

AutoIncreaseVersion fails with Error while parsing JSON - Unexpected end of JSON input

ISSUE DESCRIPTION:
Running build script deletes all contents from package.json.
Build then immediately fails with Error while parsing JSON - Unexpected end of JSON input.

VERSION INFO:

webpack-auto-inject-vesion: 1.2.2
Webpack: 4.46.0
@vue/cli 4.5.13
Vue: 2.6.14

BUILD COMMAND:

cross-env NODE_ENV=production vue-cli-service ssr:build --env.patch

PLUGIN CONFIGURATION:

new WebpackAutoInject({
  silent: false,
  components: {
    AutoIncreaseVersion: true,
    InjectAsComment: false,
    InjectByTag: false
  },
  componentsOptions: {
    AutoIncreaseVersion: {
      runInWatchMode: false // it will increase version with every single build!
    }
  }
})

PACKAGE.JSON CONTENTS

{
	"name": "vue-app",
	"version": "0.2.0",
	"private": true,
	"scripts": {
		"lint": "vue-cli-service lint",
		"serve": "vue-cli-service serve",
		"build": "vue-cli-service build",
		"ssr:serve": "vue-cli-service ssr:serve",
		"ssr:build": "cross-env NODE_ENV=production vue-cli-service ssr:build --env.patch",
		"ssr:start": "cross-env NODE_ENV=production vue-cli-service ssr:serve --mode production",
		"ssr:start:pm2": "./node_modules/.bin/pm2 start pm2.config.js && ./node_modules/.bin/pm2 logs WEB"
	},
	"dependencies": {
		"axios": "^0.21.1",
		"cors": "^2.8.5",
		"express-device": "^0.4.2",
		"express-ip": "^1.0.4",
		"imagekit": "^3.2.2",
		"imagekit-javascript": "^1.4.1",
		"node-fetch": "^3.0.0",
		"nuxtjs-sticky-sidebar": "^1.2.0",
		"shebang-loader": "^0.0.1",
		"vue": "^2.6.11",
		"vue-carousel": "^0.18.0",
		"vue-debounce": "^3.0.1",
		"vue-lazy-hydration": "^2.0.0-beta.4",
		"vue-router": "^3.2.0",
		"vue-select": "^3.12.1",
		"vue-server-renderer": "^2.6.0",
		"vue-slick-carousel": "^1.0.6",
		"vuex": "^3.4.0",
		"vuex-persist": "^3.1.3",
		"vuex-persistedstate": "^4.0.0",
		"winston": "^3.3.3"
	},
	"devDependencies": {
		"@akryum/vue-cli-plugin-ssr": "~0.6.0",
		"@vue/cli-plugin-babel": "~4.5.0",
		"@vue/cli-plugin-eslint": "~4.5.0",
		"@vue/cli-plugin-pwa": "~4.5.0",
		"@vue/cli-plugin-router": "~4.5.0",
		"@vue/cli-plugin-vuex": "~4.5.0",
		"@vue/cli-service": "~4.5.0",
		"@vue/eslint-config-airbnb": "^5.0.2",
		"babel-eslint": "^10.1.0",
		"eslint": "^6.7.2",
		"eslint-plugin-import": "^2.20.2",
		"eslint-plugin-vue": "^6.2.2",
		"express": "^4.17.1",
		"less": "^4.1.1",
		"less-loader": "^5.0.0",
		"pm2": "^5.1.1",
		"ssr-window": "^4.0.0",
		"vue-loader-v16": "^16.0.0-beta.5.4",
		"vue-server-renderer": "^2.6.14",
		"vue-template-compiler": "^2.6.11",
		"webpack-auto-inject-version": "^1.2.2",
		"webpack-bundle-analyzer": "^4.4.2",
		"webpack-shell-plugin": "^0.5.0"
	}
}

CONSOLE OUTPUT:

[AIV] :  info : Auto inject version started
 ERROR  SyntaxError: /package.json: Error while parsing JSON - Unexpected end of JSON input
SyntaxError: /package.json: Error while parsing JSON - Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at /node_modules/@babel/core/lib/config/files/package.js:55:20
    at /node_modules/@babel/core/lib/config/files/utils.js:30:12
    at Generator.next (<anonymous>)
    at Function.<anonymous> (/node_modules/@babel/core/lib/gensync-utils/async.js:24:3)
    at Generator.next (<anonymous>)
    at evaluateSync (/node_modules/gensync/index.js:251:28)
    at Function.sync (/node_modules/gensync/index.js:89:14)
    at sync (/node_modules/@babel/core/lib/gensync-utils/async.js:67:25)
    at sync (/node_modules/gensync/index.js:182:19)

MY BEST GUESS:
It seems to be a problem in babel - this function call is only passing one argument (https://github.com/babel/babel/blob/672a58660f0b15691c44582f1f3fdcdac0fa0d2f/packages/babel-core/src/config/files/package.ts#L23) whereas it seems to want the file contents passed as the second argument according to the function definition here: https://github.com/babel/babel/blob/672a58660f0b15691c44582f1f3fdcdac0fa0d2f/packages/babel-core/src/config/files/package.ts#L36

POSSIBLE SOLUTION
Use a different method to read from/write to package.json.

Issue to while adding version to build files

@radswiat : I followed the steps suggested, installed webpack-auto-inject-version, and updated the start with webpack --major, and in webpack.config.js (which is my build configuration file) i want to append the build version to the files. but am unable to do the same, can you help me if there is anything am missing.

WebpackAutoInject is not a contructor

Hi,

I'm getting error as shown below. I could fix/hack-around this by using

  • new WebpackAutoInject.default();

Probably due to exporting as default

export default class WebpackAutoInject.

Error

C:\myfolder\webpack.config.js:58
new WebpackAutoInject(),
^

TypeError: WebpackAutoInject is not a constructor
at Object. (C:\myfolder\webpack.config.js:58:9)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at requireConfig (C:\myfolder\node_modules\webpack\bin\convert-argv.js:96:18)
at C:\myfolder\node_modules\webpack\bin\convert-argv.js:109:17

Apply shouldn't be executed asynchroneously

There is a problem related to the fact that WebpackAutoInject.apply method and all following calls are done asynchronously. Currently there is no control over sequence of registering of 'emit' functions by InjectAsComment and InjectByTag.
I use another plugin compression-webpack-plugin that compresses js files at the end of bundle building flow.
Current behavior looks as follows:

  1. InjectAsComment appends version in comment to bundle.js,
  2. compress plugin compresses bundle.js to bundle.js.bz,
  3. InjectByTag replaces version tag in source code of bundle.js.
    In result I get bundle.js that contains generated version in place of [AIV] tag and bundle.js.bz that hasn't got [AIV] tag replaced.

Version auto increment does not work with Vue CLI service building

Hi,
I use Vue3 CLI service (https://cli.vuejs.org/config/#global-cli-config) for building (it chains Webpack behind the scenes).
Would you be able to advise how do I initiate version auto increments in such case?

this does not work (no surprise):

  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build --env.minor",
    "lint": "vue-cli-service lint",
    "inspect": "vue-cli-service inspect",
    "inspect > log": "vue-cli-service inspect > vue.inspect.log"
  },

Unknown argument: major

I installed webpack-auto-inject-version:

npm install webpack-auto-inject-version --save-dev

I then run:
webpack --major

I get the following error:
Unknown argument: major

Error in 0.5.5

I was so happy and then I saw this...

Any ideas?

[AIV] :  info : InjectAsComment : match : app.css : injected : 1.0.16
 95% emittingUnhandled rejection TypeError: asset.source(...).replace is not a function
    at C:\data\web\damage\node_modules\webpack-auto-inject-version\dist\WebpackAutoInjectVersion.js:649:44
    at Compiler.<anonymous> (C:\data\web\damage\node_modules\webpack-auto-inject-version\dist\WebpackAutoInjectVersion.js:657:15)
    at next (C:\data\web\damage\node_modules\tapable\lib\Tapable.js:140:14)
    at Compiler.<anonymous> (C:\data\web\damage\node_modules\webpack\lib\ProgressPlugin.js:126:5)
    at next (C:\data\web\damage\node_modules\tapable\lib\Tapable.js:140:14)
    at C:\data\web\damage\node_modules\html-webpack-plugin\index.js:205:9
    at PassThroughHandlerContext.finallyHandler (C:\data\web\damage\node_modules\bluebird\js\release\finally.js:56:23)
    at PassThroughHandlerContext.tryCatcher (C:\data\web\damage\node_modules\bluebird\js\release\util.js:16:23)
    at Promise._settlePromiseFromHandler (C:\data\web\damage\node_modules\bluebird\js\release\promise.js:512:31)
    at Promise._settlePromise (C:\data\web\damage\node_modules\bluebird\js\release\promise.js:569:18)
    at Promise._settlePromise0 (C:\data\web\damage\node_modules\bluebird\js\release\promise.js:614:10)
    at Promise._settlePromises (C:\data\web\damage\node_modules\bluebird\js\release\promise.js:693:18)
    at Async._drainQueue (C:\data\web\damage\node_modules\bluebird\js\release\async.js:133:16)
    at Async._drainQueues (C:\data\web\damage\node_modules\bluebird\js\release\async.js:143:10)
    at Immediate.Async.drainQueues [as _onImmediate] (C:\data\web\damage\node_modules\bluebird\js\release\async.js:17:14)
    at processImmediate [as _immediateCallback] (timers.js:383:17)

Customize Tag?

Would be nice if you could add a option to customize the tag.

<!-- [AIV] Build version: 0.0.1 -->

Maybe by adding something like this:
Default: [AIV] Build version: {version}
Custom: example.com - Build: {version} - Compiled: {buildDate}

{buildDate} could be "Mon Nov 23 2015 14:26:25 GMT+0100 (CET)"

Plugin runs multiple times when first running webpack.

Any idea why this plugin causes 2 or 3 additional builds when first running Webpack in watch mode? I thought it'd be because it's watching package.json which is changing but I have watchOptions:{ ignored: [/node_modules/, /package\.json/] }. Plus that would mean it would be recompiling indefinitely so it doesn't make sense.

Ability to set timezone

It would be great to be able to set the timezone for the date output, do you know if it's currently possible? My use case is my build server is in a different timezone so it's time is irrelevant to me

Version auto increment off by 1

new WebpackAutoInject({
    components: {
        AutoIncreaseVersion: true,
    },
    componentsOptions: {
        AutoIncreaseVersion: {
            runInWatchMode: true
        }
    }
}),
[AIV] :  info : InjectAsComment : match : bundle.js : injected : 0.6.14
[AIV] :  info : InjectAsComment : match : index.html : injected : 0.6.14
[AIV] :  info : InjectByTag : match : bundle.js : replaced : 1
[AIV] :  info : InjectByTag : match : index.html : replaced : 0
[AIV] :  info : autoIncVersion : new version : 0.6.15
[AIV] :  info : package.json updated!

Any idea why the injected version is 1 behind the new version?

InjectAsComment not injecting into index.html

Hi - Thanks for the module. It does what I primarily needed - getting the package version number into the webpack dist bundle. But, just reporting that it isn't adding the comment to my index.html file using the config shown below.

After running, nothing is added or different in my index.hml.

bundle.js has the comment // [AIV] Version: 2.4.0 - 9:36:36 AM (not sure why it doesn't have NAME?) as expected.

Using webpack 3.7.1 .

    new WebpackAutoInject({
      NAME: 'idb-ng',
      SILENT: true,
      PACKAGE_JSON_PATH: './package.json',
      components: {InjectAsComment: true},
      componentsOptions: {
        InjectAsComment: {
          tag: 'Version: {version} - {date}',
          dateFormat: 'h:MM:ss TT'
        },        
      }
    })

Error after upgrading to 0.5.1

I get the following error after upgrading.

Error: Cannot find module 'babel-runtime/helpers/classCallCheck'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at webpackUniversalModuleDefinition (C:\data\web\damage\node_modules\webpack-auto-inject-version\dist\WebpackAutoInjectVersion.js:3:28)
at Object. (C:\data\web\damage\node_modules\webpack-auto-inject-version\dist\WebpackAutoInjectVersion.js:10:3)
at Module._compile (module.js:397:26)
at Object.Module._extensions..js (module.js:404:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object. (C:\data\web\damage\config\webpack.common.js:5:25)
at Module._compile (module.js:397:26)
at Object.Module._extensions..js (module.js:404:10)
at Module.load (module.js:343:32)

Plugin breaks the source maps

If we enable the source maps of our code, the plugin is adding a new line over the bundle version without making necessary changes on source maps.

The result is that the debugging process is always displaced one line.

image

In the image above, Chrome dev tools wrongly think code execution is in line 121 but it is really in line 120.

InjectByTag not working with interior comma

This is in a .vue file, not sure if it behaves the same way in other files or not.

Steps to reproduce:

  • add the following to html file
[AIV]Version {version} , {date}[/AIV]

Expected outcome:

  • html contains Version 01.00.00 , Jan 15th, 2018

Actual outcome:

  • html contains [AIV]Version {version} , {date}[/AIV]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.