snowpack-plugin-build-info

A snowpack plugin to add git commit hash info the the build

Usage no npm install needed!

<script type="module">
  import snowpackPluginBuildInfo from 'https://cdn.skypack.dev/snowpack-plugin-build-info';
</script>

README

snowpack-plugin-build-info

Snowpack plugin to show git / build info (Basicaly snowpack-plugin-replace but only for git info)

Usage

Install

1 Get the plugin

(Option 1) Local dev env: Link the project to an npm package: (budget npm registry)

  1. Navigate to the plugin project folder
  2. $ npm link snowpack-plugin-build-info

(Option 2) Npm registry package (not yet): npm: $ npm install --save-dev snowpack-plugin-build-info yarn: $ yarn add -D snowpack-plugin-build-info

2 Add plugin to snowpack config Add the plugin to the snowpack config file (e.g. snowpack.config.js or snowpack.config.json):

plugins: [
  ["snowpack-plugin-build-info", {
    // ... pluginOptions
  }]
],

The following pluginOptions are available: | Option | Required | Description | Example | | - | - | - | - | | allowedExts | true | A list of file extensions where tag replacement is allowed to happen |allowedExts: ['.html', '.js', '.css'] |

Config

Add the desired tags to the HTML / JS / whatever:

<!-- In the head as meta tag: -->
<meta name="git-branch-name" content="%GIT_BRANCH_NAME%" />
<!-- Or in the main body: -->
<p>Git branch name: %GIT_BRANCH_NAME%</p>

Currently supported tags

Tag Example result
%GIT_BRANCH_NAME% master
%GIT_COMMIT_HASH_LONG% ae76d8e24aff8684504e53d281c102fbed2ab204
%GIT_COMMIT_HASH_SHORT% ae76d8e
%GIT_COMMIT_DATETIME% 2020-11-21 19:58:14
%GIT_COMMIT_DATE% 2020-11-21
%BUILD_DATETIME% 2020-11-21 21:32:32
%BUILD_DATE% 2020-11-21
%BUILD_ENV% development