-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.common.js
80 lines (70 loc) · 2.3 KB
/
webpack.common.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
const fs = require('fs');
const path = require('path');
// https://www.youtube.com/playlist?list=PLblA84xge2_zwxh3XJqy6UVxS60YdusY8
const HtmlWebpackPlugin = require('html-webpack-plugin');
const utils = require('./src/js/utils');
const fetchData = () => {
const config = require('./config');
const Games = require('./db/games.js');
const Teams = require('./db/teams.js');
const Forecasts = require('./db/forecasts.js');
const Clinches = require('./db/clinches.js');
const games = new Games();
const teams = new Teams();
const forecasts = new Forecasts();
const clinches = new Clinches();
games.teams = teams;
fs.writeFileSync(path.join(__dirname, './src/data/games.json'), JSON.stringify(games.export(config.season), null, 4));
fs.writeFileSync(path.join(__dirname, './src/data/weekly_forecasts.json'), JSON.stringify(forecasts.getWeeklyForecasts(config.season), null, 4));
fs.writeFileSync(path.join(__dirname, './src/data/clinches.json'), JSON.stringify(clinches.export(config.season), null, 4));
}
fetchData();
const weeklyForecasts = utils.forecast.add1WeekChange(require('./src/data/weekly_forecasts.json'));
const clinches = require('./src/data/clinches.json');
const games = require('./src/data/games.json');
// const processedGames = utils.games.processGames(games);
const forecast = weeklyForecasts.forecasts[0];
const templateVars = {
utils,
lastUpdated: weeklyForecasts.last_updated,
clinches,
games
}
const plugins = [
new HtmlWebpackPlugin({
template: './src/templates/index.pug',
favicon: './src/images/favicon.png',
templateParameters: Object.assign({
forecast,
weeklyForecasts: weeklyForecasts.forecasts,
page: 'standings'
}, templateVars)
}),
new HtmlWebpackPlugin({
template: './src/templates/index.pug',
filename: 'games/index.html',
favicon: './src/images/favicon.png',
templateParameters: Object.assign({ page: 'games' }, templateVars)
})
];
module.exports = {
entry: './src/js/app.js',
module: {
rules: [
// Include pug-loader to process the pug files
{
test: /\.pug$/,
use: ['pug-loader']
},
{
test: /\.(png|jpg|gif)$/i,
type: 'asset/resource'
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/i,
type: 'asset/resource'
}
]
},
plugins
};