2020-12-03 10:57:14 +01:00
|
|
|
const COMPRESS = true;
|
2019-10-20 04:40:30 +02:00
|
|
|
|
2020-12-24 23:42:33 +01:00
|
|
|
const conf = {
|
|
|
|
APPDIR: '',
|
|
|
|
SRC: 'src',
|
|
|
|
DIST: 'dist',
|
|
|
|
webp: false,
|
|
|
|
};
|
|
|
|
|
2019-06-08 17:20:51 +02:00
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
|
|
const webpack = require('webpack');
|
|
|
|
const path = require('path');
|
2019-12-10 19:11:31 +01:00
|
|
|
const filesystem = require('fs');
|
|
|
|
|
2020-05-14 19:00:21 +02:00
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
2019-10-20 03:19:20 +02:00
|
|
|
|
|
|
|
const TerserPlugin = require('terser-webpack-plugin');
|
|
|
|
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
|
2020-12-03 10:57:14 +01:00
|
|
|
const ImageminPlugin = require('image-minimizer-webpack-plugin');
|
2020-01-23 03:09:36 +01:00
|
|
|
const ImageSpritePlugin = require('@a2nt/image-sprite-webpack-plugin');
|
2019-06-08 17:20:51 +02:00
|
|
|
|
2020-09-10 20:17:07 +02:00
|
|
|
const UIInfo = require('./package.json');
|
|
|
|
const UIMetaInfo = require('./node_modules/@a2nt/meta-lightbox/package.json');
|
|
|
|
|
2020-12-24 23:42:33 +01:00
|
|
|
console.log('WebP images: ' + conf['webp']);
|
|
|
|
|
2019-10-20 04:40:30 +02:00
|
|
|
const plugins = [
|
2020-05-14 19:00:21 +02:00
|
|
|
new webpack.DefinePlugin({
|
|
|
|
'process.env': {
|
|
|
|
NODE_ENV: JSON.stringify('production'),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
new webpack.LoaderOptionsPlugin({
|
|
|
|
minimize: COMPRESS,
|
|
|
|
debug: false,
|
|
|
|
}),
|
|
|
|
new MiniCssExtractPlugin({
|
|
|
|
filename: 'css/[name].css',
|
2020-12-03 10:57:14 +01:00
|
|
|
//allChunks: true,
|
2020-05-14 19:00:21 +02:00
|
|
|
}),
|
|
|
|
/**/
|
|
|
|
new HtmlWebpackPlugin({
|
2020-12-24 23:42:33 +01:00
|
|
|
template: path.join(conf.APPDIR, conf.SRC, 'index.html'),
|
2020-05-14 19:00:21 +02:00
|
|
|
}),
|
2020-09-10 20:17:07 +02:00
|
|
|
new webpack.DefinePlugin({
|
|
|
|
UINAME: JSON.stringify(UIInfo.name),
|
|
|
|
UIVERSION: JSON.stringify(UIInfo.version),
|
|
|
|
UIAUTHOR: JSON.stringify(UIInfo.author),
|
2020-09-10 20:41:39 +02:00
|
|
|
UIMetaNAME: JSON.stringify(UIMetaInfo.name),
|
2020-09-10 20:17:07 +02:00
|
|
|
UIMetaVersion: JSON.stringify(UIMetaInfo.version),
|
|
|
|
}),
|
2019-10-20 04:40:30 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
if (COMPRESS) {
|
2020-05-14 19:00:21 +02:00
|
|
|
plugins.push(
|
|
|
|
new OptimizeCssAssetsPlugin({
|
|
|
|
//assetNameRegExp: /\.optimize\.css$/g,
|
|
|
|
cssProcessor: require('cssnano'),
|
|
|
|
cssProcessorPluginOptions: {
|
|
|
|
preset: ['default'],
|
|
|
|
},
|
|
|
|
cssProcessorOptions: {
|
|
|
|
zindex: true,
|
|
|
|
cssDeclarationSorter: true,
|
|
|
|
reduceIdents: false,
|
|
|
|
mergeIdents: true,
|
|
|
|
mergeRules: true,
|
|
|
|
mergeLonghand: true,
|
|
|
|
discardUnused: true,
|
|
|
|
discardOverridden: true,
|
|
|
|
discardDuplicates: true,
|
|
|
|
discardComments: {
|
|
|
|
removeAll: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
canPrint: true,
|
|
|
|
}),
|
|
|
|
);
|
2020-09-09 17:40:58 +02:00
|
|
|
plugins.push(require('autoprefixer'));
|
2020-01-22 10:49:07 +01:00
|
|
|
|
2020-05-14 19:00:21 +02:00
|
|
|
plugins.push(
|
|
|
|
new ImageminPlugin({
|
2020-12-03 10:57:14 +01:00
|
|
|
minimizerOptions: {
|
|
|
|
// Lossless optimization with custom option
|
|
|
|
// Feel free to experiment with options for better result for you
|
2020-05-14 19:00:21 +02:00
|
|
|
plugins: [
|
|
|
|
['gifsicle', { interlaced: true }],
|
|
|
|
['jpegtran', { progressive: true }],
|
|
|
|
['optipng', { optimizationLevel: 5 }],
|
|
|
|
[
|
|
|
|
'svgo',
|
|
|
|
{
|
|
|
|
plugins: [
|
|
|
|
{
|
|
|
|
removeViewBox: false,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
],
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
);
|
2020-01-23 03:09:36 +01:00
|
|
|
|
2020-05-14 19:00:21 +02:00
|
|
|
plugins.push(
|
|
|
|
new ImageSpritePlugin({
|
|
|
|
exclude: /exclude|original|default-|icons|sprite/,
|
|
|
|
commentOrigin: false,
|
|
|
|
compress: true,
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-12-10 19:11:31 +01:00
|
|
|
const includes = {};
|
|
|
|
|
2020-05-14 19:00:21 +02:00
|
|
|
const _addAppFiles = (theme) => {
|
|
|
|
const dirPath = path.resolve(__dirname, theme);
|
|
|
|
const themeName = path.basename(theme);
|
2019-12-10 19:11:31 +01:00
|
|
|
|
2020-05-14 19:00:21 +02:00
|
|
|
if (filesystem.existsSync(path.join(dirPath, 'js', 'app.js'))) {
|
|
|
|
includes['app'] = path.join(dirPath, 'js', 'app.js');
|
|
|
|
} else if (filesystem.existsSync(path.join(dirPath, 'scss', 'app.scss'))) {
|
|
|
|
includes['app'] = path.join(dirPath, 'scss', 'app.scss');
|
|
|
|
}
|
2019-12-10 19:11:31 +01:00
|
|
|
|
2020-05-14 19:00:21 +02:00
|
|
|
const _getAllFilesFromFolder = function (dir, includeSubFolders = true) {
|
|
|
|
const dirPath = path.resolve(__dirname, dir);
|
|
|
|
let results = [];
|
2019-12-10 19:11:31 +01:00
|
|
|
|
2020-05-14 19:00:21 +02:00
|
|
|
filesystem.readdirSync(dirPath).forEach((file) => {
|
|
|
|
if (file.charAt(0) === '_') {
|
|
|
|
return;
|
|
|
|
}
|
2019-12-10 19:11:31 +01:00
|
|
|
|
2020-05-14 19:00:21 +02:00
|
|
|
const filePath = path.join(dirPath, file);
|
|
|
|
const stat = filesystem.statSync(filePath);
|
2019-12-10 19:11:31 +01:00
|
|
|
|
2020-05-14 19:00:21 +02:00
|
|
|
if (stat && stat.isDirectory() && includeSubFolders) {
|
|
|
|
results = results.concat(
|
|
|
|
_getAllFilesFromFolder(filePath, includeSubFolders),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
results.push(filePath);
|
|
|
|
}
|
|
|
|
});
|
2019-12-10 19:11:31 +01:00
|
|
|
|
2020-05-14 19:00:21 +02:00
|
|
|
return results;
|
|
|
|
};
|
2019-12-10 19:11:31 +01:00
|
|
|
|
2020-05-14 19:00:21 +02:00
|
|
|
// add page specific scripts
|
|
|
|
const typesJSPath = path.join(theme, 'js/types');
|
|
|
|
if (filesystem.existsSync(typesJSPath)) {
|
|
|
|
const pageScripts = _getAllFilesFromFolder(typesJSPath, true);
|
|
|
|
pageScripts.forEach((file) => {
|
|
|
|
includes[`app_${path.basename(file, '.js')}`] = file;
|
|
|
|
});
|
|
|
|
}
|
2019-12-10 19:11:31 +01:00
|
|
|
|
2020-05-14 19:00:21 +02:00
|
|
|
// add page specific scss
|
|
|
|
const typesSCSSPath = path.join(theme, 'scss/types');
|
|
|
|
if (filesystem.existsSync(typesSCSSPath)) {
|
|
|
|
const scssIncludes = _getAllFilesFromFolder(typesSCSSPath, true);
|
|
|
|
scssIncludes.forEach((file) => {
|
|
|
|
includes[`app_${path.basename(file, '.scss')}`] = file;
|
|
|
|
});
|
|
|
|
}
|
2019-12-10 19:11:31 +01:00
|
|
|
};
|
|
|
|
|
2020-12-24 23:42:33 +01:00
|
|
|
_addAppFiles(path.join(conf.APPDIR, conf.SRC));
|
2019-12-10 19:11:31 +01:00
|
|
|
|
2019-06-08 17:20:51 +02:00
|
|
|
module.exports = {
|
2020-05-14 19:00:21 +02:00
|
|
|
entry: includes,
|
2020-12-24 23:42:33 +01:00
|
|
|
recordsPath: path.join(__dirname, conf.APPDIR, conf.DIST, 'records.json'),
|
|
|
|
cache: {
|
|
|
|
type: 'filesystem',
|
|
|
|
},
|
2020-05-14 19:00:21 +02:00
|
|
|
output: {
|
2020-12-24 23:42:33 +01:00
|
|
|
publicPath: path.join(conf.APPDIR),
|
|
|
|
path: path.join(__dirname, conf.APPDIR, conf.DIST),
|
2020-05-14 19:00:21 +02:00
|
|
|
filename: path.join('js', '[name].js'),
|
|
|
|
},
|
|
|
|
externals: {
|
|
|
|
jquery: 'jQuery',
|
|
|
|
},
|
|
|
|
optimization: {
|
|
|
|
splitChunks: {
|
|
|
|
name: 'vendor',
|
|
|
|
minChunks: 2,
|
|
|
|
},
|
2020-12-24 23:42:33 +01:00
|
|
|
concatenateModules: true,
|
2020-05-14 19:00:21 +02:00
|
|
|
minimizer: [
|
|
|
|
new TerserPlugin({
|
|
|
|
terserOptions: {
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
mangle: {
|
|
|
|
safari10: true,
|
2020-12-24 23:42:33 +01:00
|
|
|
/*keep_fnames: true,
|
|
|
|
keep_classnames: true,
|
|
|
|
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,
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.jsx?$/,
|
|
|
|
//exclude: /node_modules/,
|
|
|
|
use: {
|
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
|
|
|
presets: ['@babel/preset-env'], //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,
|
|
|
|
cacheCompression: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.worker\.js$/,
|
|
|
|
use: {
|
|
|
|
loader: 'worker-loader',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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'],
|
|
|
|
},
|
|
|
|
inline: {
|
|
|
|
limit: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2020-05-14 19:00:21 +02:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
modules: [
|
|
|
|
path.resolve(__dirname, 'src'),
|
|
|
|
path.resolve(__dirname, 'node_modules'),
|
|
|
|
],
|
|
|
|
alias: {
|
|
|
|
jquery: require.resolve('jquery'),
|
|
|
|
jQuery: require.resolve('jquery'),
|
|
|
|
},
|
2020-12-24 23:42:33 +01:00
|
|
|
fallback: { url: false, events: false },
|
2020-05-14 19:00:21 +02:00
|
|
|
},
|
|
|
|
plugins: plugins,
|
2019-06-08 17:20:51 +02:00
|
|
|
|
2020-05-14 19:00:21 +02:00
|
|
|
devServer: {
|
|
|
|
host: '127.0.0.1',
|
|
|
|
port: 8001,
|
|
|
|
historyApiFallback: true,
|
|
|
|
hot: false,
|
2020-12-24 23:42:33 +01:00
|
|
|
/*clientLogLevel: 'info',
|
2020-05-14 19:00:21 +02:00
|
|
|
contentBase: [
|
|
|
|
path.resolve(__dirname, 'src'),
|
|
|
|
path.resolve(__dirname, 'node_modules'),
|
|
|
|
path.resolve(__dirname, 'dist'),
|
2020-12-24 23:42:33 +01:00
|
|
|
],*/
|
2020-05-14 19:00:21 +02:00
|
|
|
//watchContentBase: true,
|
|
|
|
overlay: {
|
|
|
|
warnings: true,
|
|
|
|
errors: true,
|
|
|
|
},
|
|
|
|
headers: {
|
|
|
|
'Access-Control-Allow-Origin': '*',
|
|
|
|
},
|
|
|
|
},
|
2019-06-08 17:20:51 +02:00
|
|
|
};
|