2020-05-25 06:16:28 +02:00
|
|
|
const path = require('path');
|
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
2021-07-11 12:02:34 +02:00
|
|
|
const ImageMinimizerPlugin = require("image-minimizer-webpack-plugin");
|
2022-03-17 12:36:40 +01:00
|
|
|
const {extendDefaultPlugins} = require("svgo");
|
2020-05-25 06:16:28 +02:00
|
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
|
|
|
|
|
|
|
const dev = process.env.NODE_ENV === 'development';
|
|
|
|
|
|
|
|
const userConfig = require('./frontend/config.json');
|
|
|
|
for (const b in userConfig.bundles) {
|
|
|
|
if (userConfig.bundles.hasOwnProperty(b)) {
|
|
|
|
userConfig.bundles[b] = `./frontend/${userConfig.bundles[b]}`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const config = {
|
|
|
|
entry: userConfig.bundles,
|
|
|
|
output: {
|
2020-05-26 09:37:44 +02:00
|
|
|
path: path.resolve(__dirname, 'resources/useless-js'), // Temporary until webpack stops emitting js for css files
|
2020-05-25 06:16:28 +02:00
|
|
|
filename: '[name].js'
|
|
|
|
},
|
|
|
|
devtool: dev ? 'eval-source-map' : undefined,
|
|
|
|
target: "electron-renderer",
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.js$/i,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
|
|
|
presets: ['@babel/preset-env'],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.s[ac]ss$/i,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: MiniCssExtractPlugin.loader,
|
|
|
|
},
|
|
|
|
'css-loader',
|
|
|
|
'sass-loader',
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(woff2?|eot|ttf|otf)$/i,
|
2021-09-22 15:36:26 +02:00
|
|
|
type: 'asset/resource',
|
|
|
|
generator: {
|
|
|
|
filename: '../fonts/[name][ext]',
|
|
|
|
},
|
2020-05-25 06:16:28 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(png|jpe?g|gif|svg)$/i,
|
2021-09-22 15:36:26 +02:00
|
|
|
type: 'asset/resource',
|
|
|
|
generator: {
|
|
|
|
filename: '../images/[name][ext]',
|
|
|
|
},
|
2020-05-25 06:16:28 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.ts$/i,
|
2020-05-26 09:37:44 +02:00
|
|
|
use: {
|
|
|
|
loader: 'ts-loader',
|
|
|
|
options: {
|
|
|
|
configFile: 'tsconfig.frontend.json',
|
|
|
|
}
|
|
|
|
},
|
2021-09-22 15:36:26 +02:00
|
|
|
exclude: '/node_modules/',
|
2020-05-25 06:16:28 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.html$/i,
|
2021-09-22 15:36:26 +02:00
|
|
|
type: 'asset/resource',
|
|
|
|
generator: {
|
|
|
|
filename: '../[name][ext]',
|
|
|
|
},
|
2020-05-25 06:16:28 +02:00
|
|
|
}
|
|
|
|
],
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new MiniCssExtractPlugin({
|
|
|
|
filename: '../css/[name].css',
|
|
|
|
}),
|
|
|
|
new CopyWebpackPlugin({
|
|
|
|
patterns: [
|
|
|
|
{from: 'node_modules/@fortawesome/fontawesome-free/svgs', to: '../images/icons'}
|
|
|
|
]
|
|
|
|
}),
|
2021-07-11 12:02:34 +02:00
|
|
|
new ImageMinimizerPlugin({
|
2022-03-17 12:36:40 +01:00
|
|
|
minimizer: {
|
|
|
|
implementation: ImageMinimizerPlugin.imageminMinify,
|
|
|
|
options: {
|
|
|
|
// Lossless optimization with custom option
|
|
|
|
// Feel free to experiment with options for better result for you
|
|
|
|
plugins: [
|
|
|
|
["gifsicle", {}],
|
|
|
|
["mozjpeg", {}],
|
|
|
|
["pngquant", {}],
|
|
|
|
// Svgo configuration here https://github.com/svg/svgo#configuration
|
|
|
|
[
|
|
|
|
"svgo",
|
|
|
|
{
|
|
|
|
plugins: extendDefaultPlugins([
|
|
|
|
{
|
|
|
|
name: "removeViewBox",
|
|
|
|
active: false,
|
2021-07-11 12:02:34 +02:00
|
|
|
},
|
2022-03-17 12:36:40 +01:00
|
|
|
{
|
|
|
|
name: "addAttributesToSVGElement",
|
|
|
|
params: {
|
|
|
|
attributes: [{ xmlns: "http://www.w3.org/2000/svg" }],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]),
|
|
|
|
},
|
|
|
|
// todo: still not fixed
|
|
|
|
// {
|
|
|
|
// plugins: {
|
|
|
|
// name: 'preset-default',
|
|
|
|
// params: {
|
|
|
|
// overrides: {
|
|
|
|
// removeViewBox: {
|
|
|
|
// active: false,
|
|
|
|
// },
|
|
|
|
// addAttributesToSVGElement: {
|
|
|
|
// params: {
|
|
|
|
// attributes: [{xmlns: "http://www.w3.org/2000/svg"}],
|
|
|
|
// },
|
2021-09-22 15:12:38 +02:00
|
|
|
// },
|
|
|
|
// },
|
|
|
|
// },
|
|
|
|
// },
|
|
|
|
// },
|
2022-03-17 12:36:40 +01:00
|
|
|
],
|
2021-07-11 12:02:34 +02:00
|
|
|
],
|
2022-03-17 12:36:40 +01:00
|
|
|
},
|
2021-07-11 12:02:34 +02:00
|
|
|
},
|
|
|
|
}),
|
2020-05-25 06:16:28 +02:00
|
|
|
]
|
|
|
|
};
|
|
|
|
|
2020-09-29 20:43:41 +02:00
|
|
|
module.exports = config;
|