forked from MilordVladyslav/webpack-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
110 lines (107 loc) · 2.45 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
const path = require('path');
const glob = require('glob');
const argv = require('yargs').argv;
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const isDevelopment = argv.mode === 'development';
const isProduction = !isDevelopment;
const distPath = path.join(__dirname, '/public');
const config = {
entry: {
main: './src/js/index.js'
},
output: {
filename: 'bundle.js',
path: distPath
},
module: {
rules: [{
test: /\.html$/,
use: 'html-loader'
}, {
test: /\.js$/,
exclude: /node_modules/,
use: [{
loader: 'babel-loader'
}]
}, {
test: /\.scss$/,
exclude: /node_modules/,
use: [
isDevelopment ? 'style-loader' : MiniCssExtractPlugin.loader,
'css-loader',
{
loader: 'postcss-loader',
options: {
plugins: [
isProduction ? require('cssnano') : () => {},
require('autoprefixer')({
overrideBrowserslist: ['last 2 versions']
})
]
}
},
'sass-loader'
]
}, {
test: /images[\\\/].+\.(gif|png|jpe?g|svg)$/i,
use: [{
loader: 'file-loader',
options: {
name: 'images/[name][hash].[ext]'
}
}, {
loader: 'image-webpack-loader',
options: {
mozjpeg: {
progressive: true,
quality: 70
}
}
},
],
}, {
test: /fonts[\\\/].+\.(otf|eot|svg|ttf|woff|woff2)$/i,
use: {
loader: 'file-loader',
options: {
name: 'fonts/[name][hash].[ext]'
}
},
}]
},
plugins: [
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id].css'
}),
...glob.sync('./src/*.html')
.map(htmlFile => {
return new HtmlWebpackPlugin({
filename: path.basename(htmlFile),
template: htmlFile
});
})
],
optimization: isProduction ? {
minimizer: [
new TerserPlugin({
sourceMap: true,
terserOptions: {
compress: {
inline: false,
drop_console: true
},
}
}),
],
} : {},
devServer: {
contentBase: path.join(__dirname, 'dist'),
compress: true,
port: 9000,
host: '0.0.0.0'
}
};
module.exports = config;