2021-01-20 16:31:34 +01:00
|
|
|
/*
|
|
|
|
* Production assets generation
|
|
|
|
*/
|
2019-06-08 17:20:51 +02:00
|
|
|
const webpack = require('webpack');
|
2021-01-20 16:31:34 +01:00
|
|
|
const commonVariables = require('./webpack.configuration');
|
|
|
|
const conf = commonVariables.configuration;
|
|
|
|
const { merge } = require('webpack-merge');
|
|
|
|
const common = require('./webpack.config.common.js');
|
|
|
|
|
2019-12-10 19:11:31 +01:00
|
|
|
const filesystem = require('fs');
|
2021-01-20 16:31:34 +01:00
|
|
|
const path = require('path');
|
2019-12-10 19:11:31 +01:00
|
|
|
|
2021-01-20 16:31:34 +01:00
|
|
|
const FaviconsWebpackPlugin = require('favicons-webpack-plugin');
|
2019-10-20 03:19:20 +02:00
|
|
|
|
|
|
|
const TerserPlugin = require('terser-webpack-plugin');
|
|
|
|
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
|
2021-01-20 16:31:34 +01:00
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
|
|
|
2020-01-23 03:09:36 +01:00
|
|
|
const ImageSpritePlugin = require('@a2nt/image-sprite-webpack-plugin');
|
2021-01-20 16:31:34 +01:00
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
2019-06-08 17:20:51 +02:00
|
|
|
|
2020-09-10 20:17:07 +02:00
|
|
|
const UIInfo = require('./package.json');
|
2021-01-20 16:31:34 +01:00
|
|
|
const UIVERSION = JSON.stringify(UIInfo.version);
|
2021-01-31 11:31:35 +01:00
|
|
|
const UIMetaInfo = require('./node_modules/@a2nt/meta-lightbox-react/package.json');
|
2020-09-10 20:17:07 +02:00
|
|
|
|
2021-01-25 11:10:03 +01:00
|
|
|
const NODE_ENV = conf.NODE_ENV || process.env.NODE_ENV;
|
|
|
|
const COMPRESS = NODE_ENV === 'production' ? true : false;
|
|
|
|
|
2021-02-21 08:05:58 +01:00
|
|
|
const IP = process.env.IP || conf.HOSTNAME;
|
|
|
|
const PORT = process.env.PORT || conf.PORT;
|
|
|
|
|
2021-01-25 11:10:03 +01:00
|
|
|
console.log('NODE_ENV: ' + NODE_ENV);
|
|
|
|
console.log('COMPRESS: ' + COMPRESS);
|
2020-12-24 23:42:33 +01:00
|
|
|
console.log('WebP images: ' + conf['webp']);
|
2021-02-12 18:57:33 +01:00
|
|
|
console.log('GRAPHQL_API_KEY: ' + conf['GRAPHQL_API_KEY']);
|
2020-12-24 23:42:33 +01:00
|
|
|
|
2021-01-20 16:31:34 +01:00
|
|
|
let plugins = [
|
|
|
|
new webpack.ProvidePlugin({
|
2021-01-25 11:10:03 +01:00
|
|
|
react: 'React',
|
|
|
|
'react-dom': 'ReactDOM',
|
2021-02-18 03:12:01 +01:00
|
|
|
/*$: 'jquery',
|
|
|
|
jQuery: 'jquery',
|
2021-01-20 16:31:34 +01:00
|
|
|
Popper: ['popper.js', 'default'],
|
|
|
|
Util: 'exports-loader?Util!bootstrap/js/dist/util',
|
|
|
|
Alert: 'exports-loader?Alert!bootstrap/js/dist/alert',
|
|
|
|
Button: 'exports-loader?Button!bootstrap/js/dist/button',
|
|
|
|
Carousel: 'exports-loader?Carousel!bootstrap/js/dist/carousel',
|
|
|
|
Collapse: 'exports-loader?Collapse!bootstrap/js/dist/collapse',
|
|
|
|
Dropdown: 'exports-loader?Dropdown!bootstrap/js/dist/dropdown',
|
|
|
|
Modal: 'exports-loader?Modal!bootstrap/js/dist/modal',
|
|
|
|
Tooltip: 'exports-loader?Tooltip!bootstrap/js/dist/tooltip',
|
|
|
|
Popover: 'exports-loader?Popover!bootstrap/js/dist/popover',
|
|
|
|
Scrollspy: 'exports-loader?Scrollspy!bootstrap/js/dist/scrollspy',
|
2021-02-18 03:12:01 +01:00
|
|
|
Tab: 'exports-loader?Tab!bootstrap/js/dist/tab',*/
|
2021-01-20 16:31:34 +01:00
|
|
|
}),
|
2020-05-14 19:00:21 +02:00
|
|
|
new webpack.DefinePlugin({
|
|
|
|
'process.env': {
|
2021-01-25 11:10:03 +01:00
|
|
|
NODE_ENV: JSON.stringify(NODE_ENV),
|
2020-05-14 19:00:21 +02:00
|
|
|
},
|
2021-01-20 16:31:34 +01:00
|
|
|
UINAME: JSON.stringify(UIInfo.name),
|
|
|
|
UIVERSION: UIVERSION,
|
|
|
|
UIAUTHOR: JSON.stringify(UIInfo.author),
|
2021-01-31 10:57:40 +01:00
|
|
|
UIMetaNAME: JSON.stringify(UIMetaInfo.name),
|
|
|
|
UIMetaVersion: JSON.stringify(UIMetaInfo.version),
|
2021-02-12 18:57:33 +01:00
|
|
|
GRAPHQL_API_KEY: JSON.stringify(conf['GRAPHQL_API_KEY']),
|
2021-02-18 03:12:01 +01:00
|
|
|
SWVERSION: JSON.stringify(`sw-${new Date().getTime()}`),
|
|
|
|
BASE_HREF: JSON.stringify(`http://${IP}:${PORT}`),
|
2020-05-14 19:00:21 +02:00
|
|
|
}),
|
|
|
|
new webpack.LoaderOptionsPlugin({
|
2021-01-25 11:10:03 +01:00
|
|
|
minimize: COMPRESS,
|
|
|
|
debug: !COMPRESS,
|
2020-05-14 19:00:21 +02:00
|
|
|
}),
|
|
|
|
new MiniCssExtractPlugin({
|
|
|
|
filename: 'css/[name].css',
|
2020-12-03 10:57:14 +01:00
|
|
|
//allChunks: true,
|
2020-05-14 19:00:21 +02:00
|
|
|
}),
|
2021-01-25 11:10:03 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
if (COMPRESS) {
|
|
|
|
plugins.push(
|
|
|
|
new OptimizeCssAssetsPlugin({
|
|
|
|
//assetNameRegExp: /\.optimize\.css$/g,
|
|
|
|
cssProcessor: require('cssnano'),
|
|
|
|
cssProcessorPluginOptions: {
|
|
|
|
preset: ['default'],
|
2021-01-20 16:31:34 +01:00
|
|
|
},
|
2021-01-25 11:10:03 +01:00
|
|
|
cssProcessorOptions: {
|
|
|
|
zindex: true,
|
|
|
|
cssDeclarationSorter: true,
|
|
|
|
reduceIdents: false,
|
|
|
|
mergeIdents: true,
|
|
|
|
mergeRules: true,
|
|
|
|
mergeLonghand: true,
|
|
|
|
discardUnused: true,
|
|
|
|
discardOverridden: true,
|
|
|
|
discardDuplicates: true,
|
|
|
|
discardComments: {
|
|
|
|
removeAll: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
canPrint: true,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
plugins.push(require('autoprefixer'));
|
|
|
|
|
|
|
|
plugins.push(
|
|
|
|
new ImageSpritePlugin({
|
|
|
|
exclude: /exclude|original|default-|icons|sprite|svg|logo|favicon/,
|
|
|
|
commentOrigin: false,
|
|
|
|
compress: COMPRESS,
|
|
|
|
extensions: ['png'],
|
|
|
|
indent: '',
|
|
|
|
log: true,
|
|
|
|
//outputPath: path.join(__dirname, conf.APPDIR, conf.DIST),
|
|
|
|
outputFilename: 'img/sprite-[hash].png',
|
|
|
|
padding: 0,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
2019-10-20 04:40:30 +02:00
|
|
|
|
2021-01-20 16:31:34 +01:00
|
|
|
const indexPath = path.join(__dirname, conf.APPDIR, conf.SRC, 'index.html');
|
|
|
|
if (filesystem.existsSync(indexPath)) {
|
2020-05-14 19:00:21 +02:00
|
|
|
plugins.push(
|
2021-01-20 16:31:34 +01:00
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
publicPath: '',
|
|
|
|
template: path.join(conf.APPDIR, conf.SRC, 'index.html'),
|
2021-01-25 11:10:03 +01:00
|
|
|
templateParameters: {
|
|
|
|
NODE_ENV: NODE_ENV,
|
2021-02-16 07:45:57 +01:00
|
|
|
GRAPHQL_URL: conf['GRAPHQL_URL'],
|
2021-02-20 07:00:59 +01:00
|
|
|
STATIC_URL: conf['STATIC_URL'],
|
2021-01-25 11:10:03 +01:00
|
|
|
REACT_SCRIPTS:
|
|
|
|
NODE_ENV === 'production'
|
|
|
|
? '<script crossorigin src="https://unpkg.com/react@17/umd/react.production.min.js"></script><script crossorigin src="https://unpkg.com/react-dom@17/umd/react-dom.production.min.js"></script>'
|
|
|
|
: '<script crossorigin src="https://unpkg.com/react@17/umd/react.development.js"></script><script crossorigin src="https://unpkg.com/react-dom@17/umd/react-dom.development.js"></script>',
|
|
|
|
},
|
2020-05-14 19:00:21 +02:00
|
|
|
}),
|
|
|
|
);
|
2021-01-20 16:31:34 +01:00
|
|
|
}
|
2020-01-22 10:49:07 +01:00
|
|
|
|
2021-02-21 19:01:25 +01:00
|
|
|
const faviconPath = path.join(__dirname, conf.APPDIR, conf.SRC, 'favicon.png');
|
2021-01-20 16:31:34 +01:00
|
|
|
if (filesystem.existsSync(faviconPath)) {
|
2020-05-14 19:00:21 +02:00
|
|
|
plugins.push(
|
2021-01-20 16:31:34 +01:00
|
|
|
new FaviconsWebpackPlugin({
|
|
|
|
title: 'Webpack App',
|
|
|
|
logo: faviconPath,
|
|
|
|
prefix: '/icons/',
|
|
|
|
emitStats: false,
|
|
|
|
persistentCache: true,
|
|
|
|
inject: false,
|
|
|
|
statsFilename: path.join(
|
|
|
|
conf.APPDIR,
|
|
|
|
conf.DIST,
|
|
|
|
'icons',
|
|
|
|
'iconstats.json',
|
|
|
|
),
|
|
|
|
icons: {
|
|
|
|
android: true,
|
|
|
|
appleIcon: true,
|
|
|
|
appleStartup: true,
|
|
|
|
coast: true,
|
|
|
|
favicons: true,
|
|
|
|
firefox: true,
|
|
|
|
opengraph: true,
|
|
|
|
twitter: true,
|
|
|
|
yandex: true,
|
|
|
|
windows: true,
|
2020-05-14 19:00:21 +02:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
);
|
2019-10-20 04:40:30 +02:00
|
|
|
}
|
|
|
|
|
2021-01-20 16:31:34 +01:00
|
|
|
// add themes favicons
|
|
|
|
commonVariables.themes.forEach((theme) => {
|
|
|
|
const faviconPath = path.join(__dirname, theme, conf.SRC, 'favicon.png');
|
|
|
|
if (filesystem.existsSync(faviconPath)) {
|
|
|
|
plugins.push(
|
|
|
|
new FaviconsWebpackPlugin({
|
|
|
|
title: 'Webpack App',
|
|
|
|
logo: faviconPath,
|
|
|
|
prefix: '/' + theme + '-icons/',
|
|
|
|
emitStats: false,
|
|
|
|
persistentCache: true,
|
|
|
|
inject: false,
|
|
|
|
statsFilename: path.join(
|
|
|
|
conf.APPDIR,
|
|
|
|
conf.DIST,
|
|
|
|
theme + '-icons',
|
|
|
|
'iconstats.json',
|
|
|
|
),
|
|
|
|
icons: {
|
|
|
|
android: true,
|
|
|
|
appleIcon: true,
|
|
|
|
appleStartup: true,
|
|
|
|
coast: true,
|
|
|
|
favicons: true,
|
|
|
|
firefox: true,
|
|
|
|
opengraph: true,
|
|
|
|
twitter: true,
|
|
|
|
yandex: true,
|
|
|
|
windows: true,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
);
|
2020-05-14 19:00:21 +02:00
|
|
|
}
|
2021-02-21 19:01:25 +01:00
|
|
|
});
|
2019-12-10 19:11:31 +01:00
|
|
|
|
2021-01-20 16:31:34 +01:00
|
|
|
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
|
|
|
|
.BundleAnalyzerPlugin;
|
|
|
|
plugins.push(
|
|
|
|
new BundleAnalyzerPlugin({
|
|
|
|
analyzerMode: 'static',
|
2021-01-25 11:10:03 +01:00
|
|
|
openAnalyzer: false,
|
2021-01-20 16:31:34 +01:00
|
|
|
}),
|
|
|
|
);
|
2019-12-10 19:11:31 +01:00
|
|
|
|
2021-01-20 16:31:34 +01:00
|
|
|
const cfg = merge(common, {
|
2021-01-25 11:10:03 +01:00
|
|
|
mode: NODE_ENV,
|
2020-12-24 23:42:33 +01:00
|
|
|
cache: {
|
|
|
|
type: 'filesystem',
|
|
|
|
},
|
2021-01-20 16:31:34 +01:00
|
|
|
recordsPath: path.join(__dirname, conf.APPDIR, conf.DIST, 'records.json'),
|
2020-05-14 19:00:21 +02:00
|
|
|
optimization: {
|
2021-01-20 16:31:34 +01:00
|
|
|
//removeAvailableModules: false,
|
|
|
|
//realContentHash: false,
|
2020-05-14 19:00:21 +02:00
|
|
|
splitChunks: {
|
|
|
|
name: 'vendor',
|
|
|
|
minChunks: 2,
|
|
|
|
},
|
2021-01-20 16:31:34 +01:00
|
|
|
concatenateModules: true, //ModuleConcatenationPlugin
|
2020-05-14 19:00:21 +02:00
|
|
|
minimizer: [
|
|
|
|
new TerserPlugin({
|
|
|
|
terserOptions: {
|
2021-01-20 16:31:34 +01:00
|
|
|
module: false,
|
2020-05-14 19:00:21 +02:00
|
|
|
parse: {
|
|
|
|
// we want terser to parse ecma 8 code. However, we don't want it
|
|
|
|
// to apply any minfication steps that turns valid ecma 5 code
|
|
|
|
// into invalid ecma 5 code. This is why the 'compress' and 'output'
|
|
|
|
// sections only apply transformations that are ecma 5 safe
|
|
|
|
// https://github.com/facebook/create-react-app/pull/4234
|
|
|
|
ecma: 8,
|
|
|
|
},
|
|
|
|
compress: {
|
|
|
|
ecma: 5,
|
|
|
|
warnings: false,
|
|
|
|
// Disabled because of an issue with Uglify breaking seemingly valid code:
|
|
|
|
// https://github.com/facebook/create-react-app/issues/2376
|
|
|
|
// Pending further investigation:
|
|
|
|
// https://github.com/mishoo/UglifyJS2/issues/2011
|
|
|
|
comparisons: false,
|
|
|
|
},
|
2021-01-20 16:31:34 +01:00
|
|
|
keep_fnames: true,
|
|
|
|
keep_classnames: true,
|
|
|
|
|
2020-05-14 19:00:21 +02:00
|
|
|
mangle: {
|
|
|
|
safari10: true,
|
2021-01-20 16:31:34 +01:00
|
|
|
keep_fnames: true,
|
2020-12-24 23:42:33 +01:00
|
|
|
keep_classnames: true,
|
2021-01-20 16:31:34 +01:00
|
|
|
reserved: ['$', 'jQuery', 'jquery'],
|
2020-05-14 19:00:21 +02:00
|
|
|
},
|
|
|
|
output: {
|
|
|
|
ecma: 5,
|
|
|
|
comments: false,
|
|
|
|
// Turned on because emoji and regex is not minified properly using default
|
|
|
|
// https://github.com/facebook/create-react-app/issues/2488
|
|
|
|
ascii_only: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// Use multi-process parallel running to improve the build speed
|
|
|
|
// Default number of concurrent runs: os.cpus().length - 1
|
|
|
|
parallel: true,
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
},
|
2021-01-20 16:31:34 +01:00
|
|
|
|
|
|
|
output: {
|
|
|
|
publicPath: path.join(conf.APPDIR, conf.DIST),
|
|
|
|
path: path.join(__dirname, conf.APPDIR, conf.DIST),
|
|
|
|
filename: path.join('js', '[name].js'),
|
|
|
|
},
|
|
|
|
|
2020-05-14 19:00:21 +02:00
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.jsx?$/,
|
|
|
|
//exclude: /node_modules/,
|
|
|
|
use: {
|
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
2021-01-25 11:10:03 +01:00
|
|
|
presets: [
|
|
|
|
'@babel/preset-env',
|
|
|
|
'@babel/react',
|
|
|
|
{
|
|
|
|
plugins: [
|
|
|
|
'@babel/plugin-proposal-class-properties',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
], //Preset used for env setup
|
2020-12-03 10:57:14 +01:00
|
|
|
plugins: [['@babel/transform-react-jsx']],
|
2020-05-14 19:00:21 +02:00
|
|
|
cacheDirectory: true,
|
2021-01-20 16:31:34 +01:00
|
|
|
cacheCompression: true,
|
2020-05-14 19:00:21 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.s?css$/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: MiniCssExtractPlugin.loader,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'css-loader',
|
|
|
|
options: {
|
|
|
|
sourceMap: !COMPRESS,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'resolve-url-loader',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'sass-loader',
|
|
|
|
options: {
|
|
|
|
sourceMap: !COMPRESS,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /fontawesome([^.]+).(ttf|otf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'file-loader',
|
|
|
|
options: {
|
|
|
|
name: '[name].[ext]',
|
|
|
|
outputPath: 'fonts/',
|
|
|
|
publicPath: '../fonts/',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(ttf|otf|eot|svg|woff(2)?)$/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'file-loader',
|
|
|
|
options: {
|
|
|
|
name: '[name].[ext]',
|
|
|
|
outputPath: 'fonts/',
|
|
|
|
publicPath: '../fonts/',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
2020-12-24 23:42:33 +01:00
|
|
|
test: /\.(png|webp|jpg|jpeg|gif|svg)$/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'img-optimize-loader',
|
|
|
|
options: {
|
|
|
|
name: '[name].[ext]',
|
|
|
|
outputPath: 'img/',
|
|
|
|
publicPath: '../img/',
|
|
|
|
compress: {
|
|
|
|
// This will take more time and get smaller images.
|
|
|
|
mode: 'low', // 'lossless', 'high', 'low'
|
|
|
|
disableOnDevelopment: true,
|
|
|
|
webp: conf['webp'],
|
2021-02-21 09:17:41 +01:00
|
|
|
// loseless compression for png
|
|
|
|
optipng: {
|
|
|
|
optimizationLevel: 4,
|
|
|
|
},
|
|
|
|
// lossy compression for png. This will generate smaller file than optipng.
|
|
|
|
pngquant: {
|
|
|
|
quality: [0.2, 0.8],
|
|
|
|
},
|
|
|
|
// Compression for svg.
|
|
|
|
svgo: true,
|
|
|
|
// Compression for gif.
|
|
|
|
gifsicle: {
|
|
|
|
optimizationLevel: 3,
|
|
|
|
},
|
|
|
|
// Compression for jpg.
|
|
|
|
mozjpeg: {
|
|
|
|
progressive: true,
|
|
|
|
quality: 60,
|
|
|
|
},
|
2020-12-24 23:42:33 +01:00
|
|
|
},
|
|
|
|
inline: {
|
|
|
|
limit: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2020-05-14 19:00:21 +02:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2021-01-20 16:31:34 +01:00
|
|
|
|
2020-05-14 19:00:21 +02:00
|
|
|
plugins: plugins,
|
2021-01-20 16:31:34 +01:00
|
|
|
});
|
2019-06-08 17:20:51 +02:00
|
|
|
|
2021-01-20 16:31:34 +01:00
|
|
|
console.log(cfg);
|
|
|
|
module.exports = cfg;
|