-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
116 lines (115 loc) · 3.07 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
module.exports = (env) => ({
mode: 'production',
entry: {
bundle: path.resolve(__dirname, 'src/assets/js/index.js'),
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'assets/js/[name][contenthash].js',
clean: true,
assetModuleFilename: '[name][ext]',
},
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
}),
new HtmlWebpackPlugin({
title: 'evanesoteric',
filename: 'index.html',
template: 'src/index.html',
favicon: 'src/assets/img/favicon.webp',
inject: true,
}),
new MiniCssExtractPlugin({
filename: 'assets/css/[name].[contenthash].css',
}),
new CopyPlugin({
patterns: [
{ from: 'src/robots.txt', to: 'robots.txt' },
{ from: 'src/gpg.txt', to: 'gpg.txt' },
{ from: 'src/assets/img/favicon.webp', to: 'assets/img/favicon.webp' },
{ from: 'src/assets/img/opengraph.webp', to: 'assets/img/opengraph.webp' },
],
}),
new BundleAnalyzerPlugin(),
],
devtool: 'source-map',
devServer: {
static: {
directory: path.resolve(__dirname, 'dist'),
},
port: 3000,
open: true,
hot: true,
compress: true,
historyApiFallback: true,
client: {
logging: 'none', // Keeps the logging setting as is, to not log anything to the browser console
overlay: {
errors: true,
warnings: true, // Set this to true to enable the overlay for warnings
},
},
},
module: {
rules: [
{
test: /\.(scss|css)$/,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'],
},
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
},
},
},
{
test: /\.(png|svg|jpg|jpeg|gif|webp)$/i,
type: 'asset/resource',
generator: {
filename: 'assets/img/[name].[hash][ext][query]'
}
},
{
test: /\.(eot|svg|ttf|woff|woff2)$/,
type: 'asset/resource',
generator: {
filename: 'assets/fonts/[name].[hash][ext][query]'
}
},
{
test: /\.html$/,
loader: 'html-loader',
options: {
sources: {
list: [
{
tag: 'img',
attribute: 'src',
type: 'src',
},
],
},
minimize: true,
},
},
],
},
optimization: {
minimize: true,
minimizer: [new CssMinimizerPlugin(), '...'],
},
stats: env.ERROR_LOGGING === 'none' ? 'errors-only' : 'normal',
});