diff --git a/.gatsby/onCreateWebpackConfig.js b/.gatsby/onCreateWebpackConfig.js index 81f26634..f6d1b5b6 100644 --- a/.gatsby/onCreateWebpackConfig.js +++ b/.gatsby/onCreateWebpackConfig.js @@ -18,7 +18,9 @@ const { resolve: resolvePath } = require("path"); /* eslint-disable import/no-extraneous-dependencies */ +const webpack = require("webpack"); const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer"); +const GitRevisionPlugin = require("git-revision-webpack-plugin"); /* eslint-enable import/no-extraneous-dependencies */ const r = m => resolvePath(__dirname, m); @@ -27,6 +29,7 @@ const r = m => resolvePath(__dirname, m); * Configuration for the `webpack-bundle-analyzer` plugin. * * @type {object} + * @see https://github.com/webpack-contrib/webpack-bundle-analyzer * @since 0.1.0 */ const bundleAnalyzerPluginConfig = { @@ -37,6 +40,32 @@ const bundleAnalyzerPluginConfig = { statsFilename: r("../build/reports/webpack-bundle-analyzer/stats.json") }; +/** + * Configuration for the `git-revision-webpack-plugin` plugin. + * + * @type {object} + * @see https://github.com/pirelenito/git-revision-webpack-plugin + * @since 0.1.0 + */ +const gitRevisionPluginConfig = { + branch: true +}; + +const gitRevisionPlugin = new GitRevisionPlugin(gitRevisionPluginConfig); + +/** + * Configuration for `webpack.DefinePlugin`. + * + * @type {object} + * @see https://webpack.js.org/plugins/define-plugin + * @since 0.1.0 + */ +const definePluginConfig = { + "process.env.NORD_DOCS_GIT_VERSION": JSON.stringify(gitRevisionPlugin.version()), + "process.env.NORD_DOCS_GIT_COMMITHASH": JSON.stringify(gitRevisionPlugin.commithash()), + "process.env.NORD_DOCS_GIT_BRANCH": JSON.stringify(gitRevisionPlugin.branch()) +}; + /** * Implementation of the Gatsby Node `onCreateWebpackConfig` API. * @@ -72,7 +101,16 @@ const onCreateWebpackConfig = ({ actions, stage }) => { case "build-html": case "build-javascript": actions.setWebpackConfig({ - plugins: [new BundleAnalyzerPlugin(bundleAnalyzerPluginConfig)] + plugins: [ + new BundleAnalyzerPlugin(bundleAnalyzerPluginConfig), + new GitRevisionPlugin(), + new webpack.DefinePlugin(definePluginConfig) + ] + }); + break; + case "develop": + actions.setWebpackConfig({ + plugins: [new webpack.DefinePlugin(definePluginConfig)] }); break; } diff --git a/src/config/internal/constants.js b/src/config/internal/constants.js index fc275e32..f6dc10ca 100644 --- a/src/config/internal/constants.js +++ b/src/config/internal/constants.js @@ -17,7 +17,7 @@ /** * The absolute path of the content base directory starting from the project root. * - * @constant {String} + * @constant {string} * @since 0.1.0 */ const BASE_DIR_CONTENT = "content"; @@ -65,9 +65,9 @@ const BASE_DIR_PAGES = `${BASE_DIR_SRC}/pages`; /** * The internal type for MDX nodes. * - * @constant {String} - * @since 0.1.0 + * @constant {string} * @see https://github.com/mdx-js/mdx + * @since 0.1.0 */ const NODE_TYPE_MDX = "Mdx";