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 baseConfig from './webpack.config';
|
||||||
import env from '../src/config/env';
|
import env from '../src/config/env';
|
||||||
import StyleLintPlugin from 'stylelint-webpack-plugin';
|
import StyleLintPlugin from 'stylelint-webpack-plugin';
|
||||||
import getPackageVersion from './getPackageVersion';
|
import getPackageJson from './getPackageJson';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
...baseConfig,
|
...baseConfig,
|
||||||
|
@ -31,7 +31,7 @@ export default {
|
||||||
plugins: [
|
plugins: [
|
||||||
new webpack.DefinePlugin({
|
new webpack.DefinePlugin({
|
||||||
__DEBUG__: true,
|
__DEBUG__: true,
|
||||||
__APP_VERSION__: `"${getPackageVersion()}"`,
|
__APP_VERSION__: `"${getPackageJson('version')}"`,
|
||||||
}),
|
}),
|
||||||
new HTMLWebpackPlugin({
|
new HTMLWebpackPlugin({
|
||||||
title: 'Verdaccio',
|
title: 'Verdaccio',
|
||||||
|
|
|
@ -7,7 +7,21 @@ const baseConfig = require('./webpack.config');
|
||||||
const env = require('../src/config/env');
|
const env = require('../src/config/env');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const merge = require('webpack-merge');
|
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 = {
|
const prodConf = {
|
||||||
mode: 'production',
|
mode: 'production',
|
||||||
|
@ -24,7 +38,7 @@ const prodConf = {
|
||||||
new webpack.DefinePlugin({
|
new webpack.DefinePlugin({
|
||||||
__DEBUG__: false,
|
__DEBUG__: false,
|
||||||
'process.env.NODE_ENV': '"production"',
|
'process.env.NODE_ENV': '"production"',
|
||||||
__APP_VERSION__: `"${getPackageVersion()}"`,
|
__APP_VERSION__: `"${version}"`,
|
||||||
}),
|
}),
|
||||||
new MiniCssExtractPlugin({
|
new MiniCssExtractPlugin({
|
||||||
filename: 'style.[contenthash].css',
|
filename: 'style.[contenthash].css',
|
||||||
|
@ -38,6 +52,7 @@ const prodConf = {
|
||||||
debug: false,
|
debug: false,
|
||||||
inject: true,
|
inject: true,
|
||||||
}),
|
}),
|
||||||
|
new webpack.BannerPlugin(banner),
|
||||||
],
|
],
|
||||||
|
|
||||||
optimization: {
|
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]))
|
Array.isArray(loader.use) && loader.use.find((v) => /css/.test(v.loader.split('-')[0]))
|
||||||
).forEach((loader) => {
|
).forEach((loader) => {
|
||||||
loader.use = [MiniCssExtractPlugin.loader].concat(_.tail(loader.use));
|
loader.use = [MiniCssExtractPlugin.loader].concat(_.tail(loader.use));
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = merge(baseConfig, prodConf);
|
module.exports = merge(baseConfig, prodConf);
|
||||||
|
|
Loading…
Reference in a new issue