-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
103 lines (87 loc) · 2.03 KB
/
webpack.config.js
File metadata and controls
103 lines (87 loc) · 2.03 KB
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
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
module.exports = (env = {}) => {
const { mode = 'development' } = env;
const isProd = mode === 'production';
const isDev = mode === 'development';
const getStyleLoaders = () => ([
isProd ? MiniCssExtractPlugin.loader : 'style-loader',
'css-loader'
]);
const getPlugins = () => {
const plugins = [
new HtmlWebpackPlugin({
title: 'Hello World',
buildTime: new Date().toString(),
template: 'public/index.html'
})
];
if (isProd) {
plugins.push(
new MiniCssExtractPlugin({
filename: 'main-[hash:8].css'
})
);
}
return plugins;
};
return {
mode: isProd ? 'production' : isDev && 'development',
output: {
filename: isProd ? 'main-[hash:8].js' : undefined
},
module: {
rules: [
// Loading javascript
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
// Loading images
{
test: /\.(png|jpg|jpeg|gif|ico)$/,
use: [
{
loader: 'file-loader',
options: {
outputPath: 'images',
name: '[name]-[sha1:hash:7].[ext]'
}
}
]
},
// Loading fonts
{
test: /\.(ttf|oft|eot|woff|woff2)$/,
use: [
{
loader: 'file-loader',
options: {
outputPath: 'fonts',
name: '[name].[ext]'
}
}
]
},
// Loading CSS
{
test: /\.(css)$/,
use: getStyleLoaders()
},
// Loading SASS/SCSS
{
test: /\.(s[ca]ss)$/,
use: [
...getStyleLoaders(),
'sass-loader'
]
}
]
},
plugins: getPlugins(),
devServer: {
open: true
}
};
}