version-file-webpack-plugin
Generate version infomation file in webpack output folder
usage
npm i -D version-file-webpack-plugin
# or
yarn add -D version-file-webpack-plugin
# install dependencies
yarn
# build for production with minification
yarn build
# test
yarn test
options
options | type | default | description |
---|---|---|---|
output | string | __version.json | file path |
absolute | boolean | false | Absolute path of output |
data | object | {} |
output data |
jsonStringify.replacer | array | null | JSON.stringify replacer |
jsonStringify.space | string|number | 2 | JSON.stringify space |
writeFileOptions | object | { encoding: "utf-8", flag: "w" } |
fs.writeFile options |
config
// webpack.config.js
const VersionPlugin = require('version-file-webpack-plugin');
module.exports = {
// ...
plugins: [
new VersionPlugin({
output: '__info/version.txt', // @default `__version.json`
data: process.env,
});
],
};
nextjs
// next.config.js
module.exports = {
webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
config.plugins.push(
new versionFile({
data: process.env,
})
);
return config;
},
};
.gitignore
+/public/[output]