-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.babel.js
103 lines (101 loc) · 2.86 KB
/
webpack.config.babel.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
import path from 'path';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import { HotModuleReplacementPlugin } from 'webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import TerserJSPlugin from 'terser-webpack-plugin';
import OptimizeCssAssetsWebpackPlugin from 'optimize-css-assets-webpack-plugin';
const webpackConfiguration = (_, { mode }) => ({
entry: path.resolve('src', 'index.js'),
output: {
path: path.resolve('dist'),
filename: 'index.js',
},
// Configures Loaders
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
{
test: /.(post)?css$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
},
'css-loader',
'postcss-loader',
],
},
{
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'fonts/',
},
},
],
},
],
},
// Configures Plugins
plugins: [
new HotModuleReplacementPlugin(),
new HtmlWebpackPlugin({
template: path.resolve('src', 'index.html'),
meta: [
{
name: 'description',
content:
'Aki Gao is an Staff Software Engineer with a passion for solving difficult technical problems, delivering delightful products that empower people and leading high performing engineering teams with expertise in full-stack web application & NPM package development in TypeScript with a focus on digital asset custody, web3 & accessibility.',
},
{ name: 'author', content: 'Aki Gao' },
{
name: 'viewport',
content: 'width=device-width, height=device-height, initial-scale=1',
},
],
minify:
mode === 'production'
? {
collapseWhitespace: true,
removeComments: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
useShortDoctype: true,
}
: false,
hash: mode === 'production',
}),
new MiniCssExtractPlugin({
filename: 'style.css',
}),
],
// Configures Optimizations
optimization:
process.env.NODE_ENV === 'production'
? {
minimizer: [
new TerserJSPlugin({}),
new OptimizeCssAssetsWebpackPlugin({}),
],
}
: {},
//Configures Webpack DevServer
devServer: {
port: 8080,
// Enables webpack's Hot Module Replacement feature.
hot: true,
// Opens default browser when dev server i ran
open: true,
watchFiles: ['src/**/*'],
},
});
export default webpackConfiguration;