1
0
mirror of https://github.com/SomboChea/ui synced 2024-11-24 15:04:27 +07:00
verdaccio-ui/tools/webpack.prod.config.babel.js

82 lines
2.2 KiB
JavaScript
Raw Normal View History

2019-04-05 02:23:40 +07:00
const webpack = require('webpack');
const HTMLWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const UglifyJsWebpackPlugin = require('uglifyjs-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const baseConfig = require('./webpack.config');
const env = require('../src/config/env');
const _ = require('lodash');
const merge = require('webpack-merge');
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}
`;
2019-02-03 17:23:33 +07:00
const prodConf = {
2019-04-05 02:23:40 +07:00
mode: 'production',
2019-02-03 17:23:33 +07:00
entry: {
2019-04-05 02:23:40 +07:00
main: ['babel-polyfill', 'whatwg-fetch', `${env.SRC_ROOT}/webui/index.js`],
2019-02-03 17:23:33 +07:00
},
module: {
2019-04-05 02:23:40 +07:00
rules: [],
2019-02-03 17:23:33 +07:00
},
plugins: [
2019-04-05 02:23:40 +07:00
new webpack.DefinePlugin({
__DEBUG__: false,
'process.env.NODE_ENV': '"production"',
__APP_VERSION__: `"${version}"`,
}),
2019-02-03 17:23:33 +07:00
new MiniCssExtractPlugin({
2019-04-05 02:23:40 +07:00
filename: 'style.[contenthash].css',
2019-02-03 17:23:33 +07:00
}),
new HTMLWebpackPlugin({
2019-04-05 02:23:40 +07:00
title: 'ToReplaceByTitle',
__UI_OPTIONS: 'ToReplaceByVerdaccioUI',
2019-04-05 02:23:40 +07:00
scope: 'ToReplaceByScope',
basename: 'ToReplaceByPrefix',
2019-04-05 02:23:40 +07:00
logo: 'ToReplaceByLogo',
primary_color: 'ToReplaceByPrimaryColor',
2019-04-05 02:23:40 +07:00
filename: 'index.html',
favicon: `${env.SRC_ROOT}/webui/template/favicon.ico`,
verdaccioURL: 'ToReplaceByVerdaccio',
version_app: 'ToReplaceByVersion',
2019-04-05 02:23:40 +07:00
template: `${env.SRC_ROOT}/webui/template/index.html`,
2019-02-03 17:23:33 +07:00
debug: false,
2019-04-05 02:23:40 +07:00
inject: true,
}),
new webpack.BannerPlugin(banner),
2019-02-03 17:23:33 +07:00
],
optimization: {
minimizer: [
new UglifyJsWebpackPlugin({
2019-04-05 02:23:40 +07:00
sourceMap: true,
2019-02-03 17:23:33 +07:00
}),
2019-04-05 02:23:40 +07:00
new OptimizeCSSAssetsPlugin({}),
],
},
2019-02-03 17:23:33 +07:00
};
prodConf.module.rules = baseConfig.module.rules
2019-04-05 02:23:40 +07:00
.filter((loader) =>
Array.isArray(loader.use) && loader.use.find((v) => /css/.test(v.loader.split('-')[0]))
).forEach((loader) => {
2019-02-03 17:23:33 +07:00
loader.use = [MiniCssExtractPlugin.loader].concat(_.tail(loader.use));
});
module.exports = merge(baseConfig, prodConf);