/
webpack.common.js
115 lines (111 loc) · 2.91 KB
/
webpack.common.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
/* eslint-disable no-undef */
const path = require('path');
const fs = require('fs');
const { DefinePlugin, ProvidePlugin } = require('webpack');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const dotenv = require('dotenv');
const generateHTMLPlugin = directory => {
const HTMLFileLocation = fs.readdirSync(path.resolve(__dirname, directory));
return HTMLFileLocation.filter(file => {
return (file = file.includes('.html'));
}).map(file => {
const parts = file.split('.');
const name = parts[0];
const ext = parts[1];
return new HtmlWebpackPlugin({
filename: name + '.html',
inject: true,
scriptLoading: 'defer',
favicon: path.join(__dirname, 'src', 'public', 'favicon.ico'),
template: path.join(__dirname, 'src', 'public', name + '.' + ext)
});
});
};
const HTMLPlugin = generateHTMLPlugin(path.join(__dirname, 'src', 'public'));
module.exports = {
entry: {
main: path.join(__dirname, 'src', 'main.js'),
fontAwesome: path.join(__dirname, 'src', 'styles', 'utils', '_font.scss')
},
output: {
path: path.join(__dirname, 'build'),
filename: '[name].bundle.js',
publicPath: '/'
},
infrastructureLogging: {
level: 'info'
},
plugins: [
new CleanWebpackPlugin({
cleanAfterEveryBuildPatterns: ['*.LICENSE.txt']
}),
new DefinePlugin({
'window.env': JSON.stringify(dotenv.config().parsed)
}),
new ProvidePlugin({
process: 'process/browser'
})
].concat(HTMLPlugin),
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: ['babel-loader']
},
{
test: /\.(?:ico|gif|png|jpg|jpeg)$/i,
type: 'asset/resource',
generator: {
filename: 'img/[name].[contenthash:8][ext]'
}
},
{
test: /\.(woff(2)?|eot|ttf|otf|svg|)$/,
type: 'asset',
parser: {
dataUrlCondition: {
maxSize: 1024
}
},
generator: {
filename: 'font/[name].[contenthash:8][ext]'
}
},
{
test: /\.hbs$/,
loader: 'handlebars-loader',
options: {
helperDirs: path.join(__dirname, 'src', 'helpers', 'handlebars')
}
},
{
test: /\.html$/,
use: [
{
loader: 'html-loader',
options: {
minimize: true,
esModule: true
}
}
]
}
]
},
resolve: {
modules: [path.join(__dirname, 'src'), 'node_modules'],
extensions: ['.js', '.jsx', '.json'],
alias: {
'@': path.join(__dirname, 'src'),
process: 'process/browser'
},
fallback: {
util: require.resolve('util/'),
http: require.resolve('stream-http'),
https: require.resolve('https-browserify'),
url: require.resolve('url')
}
}
};