forked from fastfend/homepage-wisniowasu
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
216 lines (215 loc) · 6.4 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
const path = require("path");
var glob = require("glob");
const HtmlWebPackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const CopyPlugin = require("copy-webpack-plugin");
const MinifyPlugin = require("babel-minify-webpack-plugin");
const webpack = require("webpack");
var assetFunctions = require("node-sass-asset-functions");
const json = require("./package.json");
const htmlMinifyOptions = {
collapseWhitespace: true,
collapseInlineTagWhitespace: false,
conservativeCollapse: false,
preserveLineBreaks: true,
removeAttributeQuotes: false,
removeComments: false,
useShortDoctype: false,
html5: true,
};
module.exports = {
context: path.resolve(__dirname),
entry: {
main: "./src/js/global.js",
home: "./src/views/templates/home/home.js",
team: "./src/views/templates/team/team.js",
forstudent: "./src/views/templates/forstudent/forstudent.js",
contact: "./src/views/templates/contact/contact.js",
projects: "./src/views/templates/projects/projects.js",
},
output: {
path: path.resolve(__dirname, "dist"),
filename: "js/[name].[contenthash].js",
},
optimization: {
minimizer: [new OptimizeCSSAssetsPlugin({})],
},
module: {
rules: [
{
test: /\.html$/,
use: [
{
loader: "html-loader",
options: {},
},
],
},
{
test: /\.(handlebars|hbs)$/,
use: [
{
loader: "handlebars-loader",
options: {
inlineRequires: "/img/",
precompileOptions: {
knownHelpersOnly: false,
},
helperDirs: [
path.join(__dirname, "./node_modules/handlebars-helpers"),
],
partialDirs: [
path.join(__dirname, "src"),
path.join(__dirname, "src", "views"),
path.join(__dirname, "src", "views", "layouts"),
path.join(__dirname, "src", "views", "templates"),
path.join(__dirname, "src", "views", "partials"),
].concat(
glob.sync("**/", {
cwd: path.resolve(__dirname, "src", "views", "partials"),
realpath: true,
})
),
},
},
],
},
{
test: /\.js$/,
exclude: /node_modules/,
use: [
{
loader: "babel-loader",
},
],
},
{
test: /\.svg/,
use: {
loader: "svg-url-loader",
options: {},
},
},
{
test: /\.(png|jpg|jpeg|gif)$/,
include: [path.resolve(__dirname, "./src/img/projects")],
use: [
{
loader: "responsive-loader",
options: {
adapter: require("responsive-loader/sharp"),
outputPath: "static",
publicPath: "/static",
format: "jpg",
},
},
],
},
{
test: /\.(png|jpg|jpeg|gif)$/,
exclude: [path.resolve(__dirname, "./src/img/projects")],
use: [
{
loader: "responsive-loader",
options: {
adapter: require("responsive-loader/sharp"),
outputPath: "static",
publicPath: "/static",
},
},
],
},
{
test: /\.(scss|sass)$/,
use: [
"style-loader",
{
loader: MiniCssExtractPlugin.loader,
options: {
publicPath: "./scss",
hmr: process.env.NODE_ENV === "development",
},
},
"css-loader",
"postcss-loader",
{
loader: "resolve-url-loader",
options: {
keepQuery: true,
},
},
{
loader: "sass-loader",
options: {
sourceMap: true,
functions: assetFunctions({
images_path: "src/img",
http_images_path: "/img",
}),
},
},
],
},
],
},
plugins: [
new CleanWebpackPlugin(),
new MiniCssExtractPlugin({
filename: "css/[name].[contenthash].css",
chunkFilename: "[id].css",
}),
new HtmlWebPackPlugin({
title: `Wiśniowa SU | Samorząd Uczniowski`,
desc:
"Poznaj samorząd uczniowski z Technikum Mechatronicnego nr 1 w Warszawie, którego połączyła chęć zmian. Zobacz jaki jest samorząd na Wiśniowej 56!",
template: "./src/views/templates/home/home.hbs",
filename: "./index.html",
chunks: ["main", "home"],
version: json.version,
minify: htmlMinifyOptions,
}),
new HtmlWebPackPlugin({
title: `Zespoł - Wiśniowa SU | Samorząd Uczniowski`,
desc: "Aktualny skład zespołu SU",
template: "./src/views/templates/team/team.hbs",
filename: "./team/index.html",
chunks: ["main", "team"],
version: json.version,
minify: htmlMinifyOptions,
}),
new HtmlWebPackPlugin({
title: `Dla ucznia - Wiśniowa SU | Samorząd Uczniowski`,
desc: "Materiały oraz usługi przeznaczone dla uczniów Wiśniowej",
template: "./src/views/templates/forstudent/forstudent.hbs",
filename: "./forstudent/index.html",
chunks: ["main", "forstudent"],
version: json.version,
minify: htmlMinifyOptions,
}),
new HtmlWebPackPlugin({
title: `Projekty - Wiśniowa SU | Samorząd Uczniowski`,
desc: "Zbiór ukończonych projektów SU Wiśniowej",
template: "./src/views/templates/projects/projects.hbs",
filename: "./projects/index.html",
chunks: ["main", "projects"],
version: json.version,
minify: htmlMinifyOptions,
}),
new HtmlWebPackPlugin({
title: `Kontakt - Wiśniowa SU | Samorząd Uczniowski`,
desc: "Dane kontakowe",
template: "./src/views/templates/contact/contact.hbs",
filename: "./contact/index.html",
chunks: ["main", "contact"],
version: json.version,
minify: htmlMinifyOptions,
}),
new CopyPlugin([{ from: "./src/static" }]),
new MinifyPlugin(),
],
devServer: {
contentBase: path.join(__dirname, "dist"),
},
};