gen-buildinfo-webpack-plugin
Generate a buildinfo.json file to public directory.
Installation
# Webpack (CRA)
yarn add -D gen-buildinfo-webpack-plugin
# Next.js
yarn add gen-buildinfo-webpack-plugin
Usage
Webpack (CRA)
// webpack.config.js
const GenBuildinfoWebpackPlugin = require('gen-buildinfo-webpack-plugin');
new GenBuildinfoWebpackPlugin({
package: require('./package.json'),
//
// [Options]
// fileDir: PROJECT_PUBLIC_DIR,
// fileName: 'buildinfo.json',
// commitHashLength: 4,
})
Next.js
// next.config.js
// use `process.env.NEXT_PUBLIC_BUILD_INFO`
const { getBuildInfo } = require('gen-buildinfo-webpack-plugin');
module.exports = {
env: {
NEXT_PUBLIC_BUILD_INFO: JSON.stringify(
getBuildInfo({ package: require('./package.json') }),
),
},
webpack(webpackConfig) {
return webpackConfig;
},
// ....
}
Output
const { getBuildInfo } = require('gen-buildinfo-webpack-plugin');
// {
// "PKG_NAME": "demo",
// "AUTHOR": "Jason Feng <solidzoro[#]live.com>",
// "VERSION": "2.66.1",
// "BUILD_NUMBER": 2066001,
// "BUILD_TIME": "20230406-142929",
// "COMMIT_HASH": "c6ed"
// };
const buildInfo = getBuildInfo({ package: require('../../package.json') });
License
MIT © Jason Feng