2021-08-02 17:05:36 -04:00
|
|
|
/**
|
|
|
|
* Webpack main configuration file
|
|
|
|
*/
|
|
|
|
|
|
|
|
const path = require('path');
|
|
|
|
const fs = require('fs');
|
|
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
|
|
|
const HTMLWebpackPlugin = require('html-webpack-plugin');
|
|
|
|
const ImageMinimizerPlugin = require('image-minimizer-webpack-plugin');
|
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
|
|
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
|
|
|
const { extendDefaultPlugins } = require('svgo');
|
|
|
|
|
|
|
|
const environment = require('./configuration/environment');
|
|
|
|
|
|
|
|
const templateFiles = fs.readdirSync(environment.paths.source)
|
|
|
|
.filter((file) => path.extname(file).toLowerCase() === '.html');
|
|
|
|
|
|
|
|
const htmlPluginEntries = templateFiles.map((template) => new HTMLWebpackPlugin({
|
|
|
|
inject: true,
|
|
|
|
hash: false,
|
|
|
|
filename: template,
|
|
|
|
template: path.resolve(environment.paths.source, template),
|
2021-08-02 17:48:22 -04:00
|
|
|
favicon: path.resolve(environment.paths.source, 'err_images', 'favicon.ico'),
|
2021-08-02 17:05:36 -04:00
|
|
|
}));
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
entry: {
|
2021-08-02 17:48:22 -04:00
|
|
|
app: path.resolve(environment.paths.source, 'err_js', 'app.js'),
|
2021-08-02 17:05:36 -04:00
|
|
|
},
|
|
|
|
output: {
|
2021-08-02 17:48:22 -04:00
|
|
|
filename: 'err_js/[name].js',
|
2021-08-02 17:05:36 -04:00
|
|
|
path: environment.paths.output,
|
2021-08-02 17:48:22 -04:00
|
|
|
publicPath: '/',
|
2021-08-02 17:05:36 -04:00
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.((c|sa|sc)ss)$/i,
|
|
|
|
use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader', 'postcss-loader'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.js$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: ['babel-loader'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(png|gif|jpe?g|svg)$/i,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'url-loader',
|
|
|
|
options: {
|
|
|
|
name: 'images/design/[name].[hash:6].[ext]',
|
|
|
|
publicPath: '../',
|
|
|
|
limit: environment.limits.images,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(eot|ttf|woff|woff2)$/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'url-loader',
|
|
|
|
options: {
|
|
|
|
name: 'fonts/[name].[hash:6].[ext]',
|
|
|
|
publicPath: '../',
|
|
|
|
limit: environment.limits.fonts,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new MiniCssExtractPlugin({
|
2021-08-02 17:48:22 -04:00
|
|
|
filename: 'err_css/[name].css',
|
2021-08-02 17:05:36 -04:00
|
|
|
}),
|
|
|
|
new ImageMinimizerPlugin({
|
|
|
|
test: /\.(jpe?g|png|gif|svg)$/i,
|
|
|
|
minimizerOptions: {
|
|
|
|
// Lossless optimization with custom option
|
|
|
|
// Feel free to experiment with options for better result for you
|
|
|
|
plugins: [
|
|
|
|
['gifsicle', { interlaced: true }],
|
|
|
|
['jpegtran', { progressive: true }],
|
|
|
|
['optipng', { optimizationLevel: 5 }],
|
|
|
|
['svgo', { configFile: path.resolve('svgo.config.js'), },
|
|
|
|
],
|
|
|
|
],
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
new CleanWebpackPlugin({
|
|
|
|
verbose: true,
|
|
|
|
cleanOnceBeforeBuildPatterns: ['**/*', '!stats.json'],
|
|
|
|
}),
|
|
|
|
new CopyWebpackPlugin({
|
|
|
|
patterns: [
|
|
|
|
{
|
2021-08-02 17:48:22 -04:00
|
|
|
from: path.resolve(environment.paths.source, 'err_images', 'content'),
|
|
|
|
to: path.resolve(environment.paths.output, 'err_images', 'content'),
|
2021-08-02 17:05:36 -04:00
|
|
|
toType: 'dir',
|
|
|
|
globOptions: {
|
|
|
|
ignore: ['*.DS_Store', 'Thumbs.db'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
].concat(htmlPluginEntries),
|
|
|
|
target: 'web',
|
|
|
|
};
|