-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
107 lines (98 loc) · 2.41 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
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const isDevelopment = process.env.NODE_ENV !== "production";
const dirSrc = path.join(__dirname, "src");
const dirBuild = path.join(__dirname, "build");
const dirNode = path.join(__dirname, "node_modules");
module.exports = {
resolve: {
modules: [dirNode, dirSrc, dirBuild]
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: "babel-loader",
include: path.join(__dirname, "scr/js")
},
{
test: /\.(png|jpg|jpeg|svg)$/,
exclude: /node_modules/,
use: [
{
loader: 'file-loader',
options: {
name: './public/imgs/[name].[ext]'
}
}
]
},
{
test: /\.(woff2?|ttf|otf|eot)$/,
exclude: /node_modules/,
use: [
{
loader: 'file-loader',
options: {
name: './public/fonts/[name].[ext]'
}
}
]
},
{
test: /\.scss$/,
exclude: /node_modules/,
use: [
{
loader: isDevelopment ? "style-loader" : MiniCssExtractPlugin.loader
},
{ loader: "css-loader" },
{
loader: "postcss-loader",
},
{
loader: "sass-loader",
}
],
include: path.join(__dirname, "src/scss")
},
{
test: /\.ejs$/i,
use: [{
loader: 'html-loader', // loader for html files goes here
}, {
loader: 'ejs-plain-loader'
}]
}
]
},
optimization: {
runtimeChunk: true
},
// For every new page add info here
plugins: [
customHtmlWebpackPlugin({
filename: "index.html",
template: "./src/views/index.ejs",
}),
customHtmlWebpackPlugin({
filename: "page2.html",
template: "./src/views/page2.ejs",
}),
new MiniCssExtractPlugin({
filename: isDevelopment ? "[name].[ext]" : "[name].[contenthash].css"
})
]
};
function customHtmlWebpackPlugin(specificOptions) {
const defaults = {
hash: !isDevelopment,
minify: {
removeComments: !isDevelopment,
collapseWhitespace: !isDevelopment
}
};
return new HtmlWebpackPlugin({ ...defaults, ...specificOptions });
}