-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
101 lines (94 loc) · 3.34 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
import path from "path";
import {fileURLToPath} from "url";
import HtmlWebpackPlugin from 'html-webpack-plugin';
import {CleanWebpackPlugin} from 'clean-webpack-plugin';
import fs from "fs";
const __filename = fileURLToPath(import.meta.url);
const __dirnamePath = path.dirname(__filename);
const users = JSON.parse(fs.readFileSync(path.join(__dirnamePath, "data/users.json"), "utf8"));
const title = "title";
const allNews = JSON.parse(fs.readFileSync(path.join(__dirnamePath, "data/news.json"), "utf8"));
const friendsNews = allNews.filter(n => users[0].friends && users[0].friends.includes(n.author_id));
const userNews = allNews.filter(n => n.author_id === users[0].id);
const combinedNews = [...userNews, ...friendsNews];
combinedNews.sort((a, b) => new Date(b.date) - new Date(a.date));
const friends = users.filter(u => users[0].friends.includes(u.id));
export default {
entry: './js/main.js',
output: {
filename: 'bundle.js',
path: path.resolve(process.cwd(), 'dist'),
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
},
},
},
{
test: /\.pug$/,
loader: "pug-loader",
options: {
pretty: true
}
},
{
test: /\.scss$/,
use: [
'style-loader', // Вставка стилей в DOM
'css-loader', // Преобразование CSS в CommonJS
'sass-loader' // Компиляция SCSS в CSS
]
}
],
},
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
filename: 'editUserTemplate.html',
template: './pages/editUser.pug',
inject: 'body',
chunks: ['main', 'editUserTemplate'],
templateParameters: {user: users[0]}
}),
new HtmlWebpackPlugin({
filename: 'friendsTemplate.html',
template: './pages/friends.pug',
inject: 'body',
chunks: ['main', 'friendsTemplate'],
templateParameters: {friends: friends, title: title}
}),
new HtmlWebpackPlugin({
filename: 'friendsNewsTemplate.html',
template: './pages/friendsNews.pug',
inject: 'body',
chunks: ['main', 'friendsNewsTemplate'],
templateParameters: {news: combinedNews, title: title, users:users, user: users[0]}
}),
new HtmlWebpackPlugin({
filename: 'newUserTemplate.html',
template: './pages/newUser.pug',
inject: 'body',
chunks: ['main', 'newUserTemplate'],
templateParameters: {title: title}
}),
new HtmlWebpackPlugin({
filename: 'Template.html',
template: './pages/newUser.pug',
inject: 'body',
chunks: ['main', 'userListTemplate'],
templateParameters: {title: title}
}),
],
resolve: {
extensions: ['.js', '.scss', '.pug'],
},
devtool: 'source-map',
mode: 'development',
};