{"id":20806726,"url":"https://github.com/fed/webpack-version-file","last_synced_at":"2025-06-22T23:03:53.657Z","repository":{"id":44466402,"uuid":"74912671","full_name":"fed/webpack-version-file","owner":"fed","description":"Generate a text file with your package name, deployed version and build date","archived":false,"fork":false,"pushed_at":"2023-01-16T13:43:29.000Z","size":336,"stargazers_count":25,"open_issues_count":5,"forks_count":9,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-07T04:46:51.409Z","etag":null,"topics":["webpack","webpack-plugin"],"latest_commit_sha":null,"homepage":"https://npm.im/webpack-version-file","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fed.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-11-27T20:34:52.000Z","updated_at":"2024-08-15T23:32:27.000Z","dependencies_parsed_at":"2023-02-10T03:46:15.632Z","dependency_job_id":null,"html_url":"https://github.com/fed/webpack-version-file","commit_stats":null,"previous_names":["fknussel/webpack-version-file"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fed%2Fwebpack-version-file","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fed%2Fwebpack-version-file/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fed%2Fwebpack-version-file/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fed%2Fwebpack-version-file/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fed","download_url":"https://codeload.github.com/fed/webpack-version-file/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252816520,"owners_count":21808702,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["webpack","webpack-plugin"],"created_at":"2024-11-17T19:24:56.439Z","updated_at":"2025-05-07T04:46:58.134Z","avatar_url":"https://github.com/fed.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# webpack-version-file\n\n[![Build Status](https://travis-ci.org/fknussel/webpack-version-file.svg)](https://travis-ci.org/fknussel/webpack-version-file)\n[![Downloads](https://img.shields.io/npm/dm/webpack-version-file.svg)](https://www.npmjs.com/package/webpack-version-file)\n[![Version](https://img.shields.io/npm/v/webpack-version-file.svg)](https://www.npmjs.com/package/webpack-version-file)\n[![License](https://img.shields.io/github/license/fknussel/webpack-version-file.svg)](https://opensource.org/licenses/MIT)\n\nThis is a simple [Webpack](https://webpack.js.org/) plugin which generates a file with your package name, version number, build date and any other details you might need. This is particularly useful as a way to know which version of your project is deployed at any given time.\n\nHere's an example of an automatically generated `version.txt` file, which you can deploy next to your bundle file:\n\n```\nyour-project-name@1.0.0\nBuild date: Mon Nov 28 2016 08:12:34 GMT+1100 (AEDT)\n```\n\n## Installation\n\n```\n# npm\nnpm install --save-dev webpack-version-file\n\n# yarn\nyarn add --dev webpack-version-file\n```\n\n## Setting up the plugin in your Webpack config file\n\nJust include the module at the top of your `webpack.config.js` file and add a new entry to your `plugins` array:\n\n```js\nconst VersionFile = require('webpack-version-file');\n\nmodule.exports = {\n  entry: './src',\n  ...\n  plugins: [\n    new VersionFile()\n  ]\n};\n```\n\nYou can also pass in additional options:\n\n```js\nconst VersionFile = require('webpack-version-file');\n\nmodule.exports = {\n  entry: './src',\n  ...\n  plugins: [\n    new VersionFile({\n      output: './build/version.txt',\n      package: './package.json'\n    })\n  ]\n};\n```\n\nAvailable options are:\n\n| Option | Description |\n|--------|-------------|\n| `output` | Path to the output file the plugin will generate. It defaults to `./version.txt`. |\n| `package` | Path to the `package.json` file. It defaults to `./package.json`. |\n| `template` | Path to the template file, e.g.: `./version.ejs`. Has no default value. |\n| `templateString` | Defaults to `\u003c%= name %\u003e@\u003c%= version %\u003e\\nBuild date: \u003c%= buildDate %\u003e` |\n| `data` | Object with additional data to be passed in to the template |\n| `verbose` | Log a success message to the terminal once the version file has been generated. `false` by default. |\n\n## Custom Data\n\nBy default, within your template you have access to all of the fields in your `package.json` with no extra configuration, e.g.:\n\n* `version`\n* `name`\n* `license`\n* `author`\n* `repository.url`\n* etc.\n\n```\n\u003c%= name %\u003e@\u003c%= version %\u003e\nLicense: \u003c%= license %\u003e\nAuthor: \u003c%= author.name %\u003e (\u003c%= author.email %\u003e)\n```\n\nHowever you can also pass in custom data when you add `webpack-version-file` to your list of plugins:\n\n```js\nconst VersionFile = require('webpack-version-file');\n\nmodule.exports = {\n  entry: './src',\n  ...\n  plugins: [\n    new VersionFile({\n      data: {\n        date: new Date(),\n        environment: process.env.NODE_ENV || 'development'\n      }\n    })\n  ]\n};\n```\n\nOnce you've set your custom chunks of data, you can reference them in your template by using the same name you've given them:\n\n```\n\u003c%= name %\u003e@\u003c%= version %\u003e\nBuild date: \u003c%= date %\u003e\nEnvironment: \u003c%= environment %\u003e\n```\n\nNote that in this example, the only two variables coming from your `package.json` file are `name` and `version`. `date` and `environment` are defined in your `data` object.\n\n## Predefined Variables\n\nThere's a single predefined variable you can make use of: `buildDate` (which is also part of the default template). The plugin itself is in charge of putting this variable into scope, and its value is generated using `new Date()`.\n\n```\n\u003c%= name %\u003e@\u003c%= version %\u003e\nBuild date: \u003c%= buildDate %\u003e\n```\n\n## Custom Templates\n\nThere are two ways in which you can define your own template:\n\n* using a template string\n* creating a template file\n\nIn either case, the template must be written using [EJS](http://www.embeddedjs.com/) which is a JavaScript templating language. Here's a sample template:\n\n```\n\u003c%= name %\u003e@\u003c%= version %\u003e\nBuild date: \u003c%= buildDate %\u003e\nComments: \u003c%= comments %\u003e\n```\n\nwhere `name` and `version` both come from the `package.json` file, `buildTime` is a variable injected by this library and `comments` is a custom variable set on the `webpack.config.js` file as part of the `data` object on your plugin definition.\n\nThis template can also be written inline in case you don't want an extra file on your project. The only difference is that you need to use the `\\n` character instead of line breaks:\n\n```\n\u003c%= name %\u003e@\u003c%= version %\u003e\\nBuild date: \u003c%= buildTime %\u003e\\nComments: \u003c%= comments %\u003e\n```\n\nIf you don't define a template altogether, it will default to:\n\n```\n\u003c%= name %\u003e@\u003c%= version %\u003e\nBuild date: \u003c%= buildDate %\u003e\n```\n\n## Running the Example\n\nClone this repo, move to the `example` folder and download the dependencies:\n\n```\ncd example\nnpm install\n```\n\nTo check how the plugin behaves with Webpack Dev Server, run:\n\n```\nnpm start\n```\n\nTo trigger the plugin when building the bundle with Webpack, run:\n\n```\nnpm run build\n```\n\n## Credits\n\nThis plugin was inspired by [morficus/version-file](https://github.com/morficus/version-file).\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffed%2Fwebpack-version-file","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffed%2Fwebpack-version-file","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffed%2Fwebpack-version-file/lists"}