-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
112 lines (102 loc) · 3.03 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
111
112
const NODE_ENV = process.env.NODE_ENV || "development";
const webpack = require("webpack");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const HtmlWebPackPlugin = require("html-webpack-plugin");
const extractLess = new MiniCssExtractPlugin({
filename: "[name].[hash].css",
disable: NODE_ENV === "development",
});
module.exports = {
mode: NODE_ENV,
entry: "./src/app.js",
output: {
path: `${__dirname}/dist`,
filename: "bundle.js",
},
devtool: NODE_ENV === "development" ? "cheap-inline-module-source-map" : "source-map",
plugins: [
new HtmlWebPackPlugin({
template: "./public/index.html",
filename: "./index.html",
}),
// new webpack.HotModuleReplacementPlugin(),
extractLess,
],
module: {
rules: [
{
test: /\.html$/,
use: {
loader: "html-loader",
options: {
minimize: true,
},
},
},
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: "babel-loader",
options: {
presets: [
["env", {
targets: {
browsers: "> 5%", // adaptation for browsers with a share of more than 5%
},
}],
],
},
},
},
{
test: /\.(c|le)ss$/,
use: [
NODE_ENV === "development" ? "style-loader" : MiniCssExtractPlugin.loader,
"css-loader",
"postcss-loader",
"less-loader",
],
},
{
test: /\.(png|jpg|gif)$/,
use: [
{
loader: "file-loader",
options: {
name: "./images/[name].[ext]",
},
},
{
loader: "url-loader",
options: {
name: "./images/[name].[ext]",
limit: 10000,
},
},
],
},
],
},
resolve: { // rules for loading modules
modules: ["node_modules"],
extensions: [".js"],
},
resolveLoader: { // rules for loading loaders
modules: ["node_modules"],
extensions: [".js"],
},
devServer: {
hot: true,
},
};
if (NODE_ENV === "production") {
module.exports.plugins.push(
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
drop_console: true,
},
}),
);
}