-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
96 lines (89 loc) · 2.26 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
const path = require('path');
const webpack = require('webpack');
const webpackDevServer = require('webpack-dev-server');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const WebpackNotifierPlugin = require('webpack-notifier');
const FriendlyErrors = require('friendly-errors-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const port = process.env.DEV_SERVER || 3000;
const isDev = process.env.NODE_ENV !== 'production';
const webpackConfig = {
entry: path.resolve(__dirname, './src/scripts/App.js'),
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'app.min.js'
},
watch: isDev,
mode: process.env.NODE_ENV,
devtool: isDev && 'inline-source-map',
module: {
rules: [
{
test: /\.html$/i,
loader: 'html-loader'
},
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader'
},
{
test: /\.scss$/i,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader',
{
loader: 'sass-loader',
options: {
sourceMap: isDev
}
}
]
},
{
test: /\.(ico|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2)(\?.*)?$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]'
}
}
]
}
]
},
plugins: [
new HtmlWebpackPlugin({
inject: true,
filename: 'index.html',
template: path.resolve(__dirname, '/src/index.html')
}),
new MiniCssExtractPlugin({
filename: 'app.min.css'
}),
new WebpackNotifierPlugin({
title: 'Webpack',
excludeWarnings: true,
alwaysNotify: true
}),
new FriendlyErrors(),
new CleanWebpackPlugin()
]
};
const devServerConfig = {
quiet: true,
writeToDisk: true,
port,
hot: true,
host: '0.0.0.0',
open: true
};
const compiler = webpack(webpackConfig, () => console.log());
if (isDev) {
// eslint-disable-next-line new-cap
const server = new webpackDevServer(compiler, devServerConfig);
server.listen(port, 'localhost');
}