mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-16 21:56:25 -05:00
fix: adds webpack banner plugin to tag bundles with version (#784)
refactor: updates let to const in generateBanner module refactor: adds getPackageJson module to get vlues from package.json refactor: adds jsdoc comments in getPackageJson module
This commit is contained in:
parent
197aecbe4d
commit
dac28d31dd
4 changed files with 45 additions and 14 deletions
25
tools/getPackageJson.js
Normal file
25
tools/getPackageJson.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
/**
|
||||
* A module to get package informations from package.json
|
||||
* @module getPackageJson
|
||||
* @param {...string} keys from package.json if no arguments passed it returns package.json content as object
|
||||
* @returns {object} with given keys or content of package.json as object
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns package info
|
||||
*/
|
||||
const getPackageJson = function(...args) {
|
||||
const packageJSON = JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json')));
|
||||
if (!args.length) {
|
||||
return packageJSON;
|
||||
}
|
||||
return args.reduce((out, key) => {
|
||||
out[key] = packageJSON[key];
|
||||
return out;
|
||||
}, {});
|
||||
};
|
||||
|
||||
module.exports = getPackageJson;
|
|
@ -1,9 +0,0 @@
|
|||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
export default function getPackageVersion() {
|
||||
let packageJSON = JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json')));
|
||||
|
||||
return packageJSON.version;
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@ import FriendlyErrorsPlugin from 'friendly-errors-webpack-plugin';
|
|||
import baseConfig from './webpack.config';
|
||||
import env from '../src/config/env';
|
||||
import StyleLintPlugin from 'stylelint-webpack-plugin';
|
||||
import getPackageVersion from './getPackageVersion';
|
||||
import getPackageJson from './getPackageJson';
|
||||
|
||||
export default {
|
||||
...baseConfig,
|
||||
|
@ -31,7 +31,7 @@ export default {
|
|||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
__DEBUG__: true,
|
||||
__APP_VERSION__: `"${getPackageVersion()}"`,
|
||||
__APP_VERSION__: `"${getPackageJson('version')}"`,
|
||||
}),
|
||||
new HTMLWebpackPlugin({
|
||||
title: 'Verdaccio',
|
||||
|
|
|
@ -7,7 +7,21 @@ const baseConfig = require('./webpack.config');
|
|||
const env = require('../src/config/env');
|
||||
const _ = require('lodash');
|
||||
const merge = require('webpack-merge');
|
||||
import getPackageVersion from './getPackageVersion';
|
||||
const getPackageJson = require('./getPackageJson');
|
||||
|
||||
const {
|
||||
version,
|
||||
name,
|
||||
license,
|
||||
} = getPackageJson('version', 'name', 'license');
|
||||
|
||||
const banner = `
|
||||
Name: [name]
|
||||
Generated on: ${Date.now()}
|
||||
Package: ${name}
|
||||
Version: v${version}
|
||||
License: ${license}
|
||||
`;
|
||||
|
||||
const prodConf = {
|
||||
mode: 'production',
|
||||
|
@ -24,7 +38,7 @@ const prodConf = {
|
|||
new webpack.DefinePlugin({
|
||||
__DEBUG__: false,
|
||||
'process.env.NODE_ENV': '"production"',
|
||||
__APP_VERSION__: `"${getPackageVersion()}"`,
|
||||
__APP_VERSION__: `"${version}"`,
|
||||
}),
|
||||
new MiniCssExtractPlugin({
|
||||
filename: 'style.[contenthash].css',
|
||||
|
@ -38,6 +52,7 @@ const prodConf = {
|
|||
debug: false,
|
||||
inject: true,
|
||||
}),
|
||||
new webpack.BannerPlugin(banner),
|
||||
],
|
||||
|
||||
optimization: {
|
||||
|
@ -55,6 +70,6 @@ prodConf.module.rules = baseConfig.module.rules
|
|||
Array.isArray(loader.use) && loader.use.find((v) => /css/.test(v.loader.split('-')[0]))
|
||||
).forEach((loader) => {
|
||||
loader.use = [MiniCssExtractPlugin.loader].concat(_.tail(loader.use));
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = merge(baseConfig, prodConf);
|
||||
|
|
Loading…
Reference in a new issue