-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
78 lines (74 loc) · 2.78 KB
/
webpack.config.js
File metadata and controls
78 lines (74 loc) · 2.78 KB
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
const path = require('path');
const fs = require('fs');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
// Define your JS entry points
const entries = {
index: '/static/js/index.js',
archives: '/static/js/archives.js',
play_recording: '/static/js/play_recording.js',
play_live: '/static/js/play_live.js',
broadcasting_page: '/static/js/broadcasting_page.js',
broadcasting_guide: '/static/js/broadcasting_guide.js',
listeners_page: '/static/js/listeners_page.js',
privacy: '/static/js/privacy.js',
faq: '/static/js/faq.js',
error: '/static/js/error.js',
};
// Generate HTMLWebpackPlugin instances dynamically for each entry
const htmlPlugins = Object.keys(entries)
.map(entryName => {
const templatePath = path.resolve(__dirname, `./templates/${entryName}.html`);
if (fs.existsSync(templatePath)) {
return new HtmlWebpackPlugin({
template: templatePath, // Use template for the specific entry
filename: `html/${entryName}.html`, // Output HTML in `dist/html`
chunks: [entryName], // Link the entry's JS and CSS to this HTML
});
} else {
console.warn(`Warning: Template for ${entryName} does not exist. Skipping...`);
return null;
}
})
.filter(Boolean); // Filter out null entries
module.exports = {
entry: entries, // JavaScript entry points
output: {
filename: 'static/js/[name].bundle.js', // JS output in `dist/static/js`
path: path.resolve(__dirname, 'dist'),
publicPath: '/dist/', // Adjust public path if needed
},
mode: 'production', // Use 'development' during local dev if needed
module: {
rules: [
// JavaScript loader
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
},
},
// CSS loader
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader'], // Extract CSS to separate files
},
// Assets loader (e.g., images, fonts)
{
test: /\.(png|jpe?g|gif|svg|woff2?|eot|ttf|otf)$/i,
type: 'asset/resource',
generator: {
filename: 'static/assets/[name][ext]', // Save assets in `dist/static/assets`
},
},
],
},
plugins: [
// Extract CSS into separate files
new MiniCssExtractPlugin({
filename: 'static/css/[name].bundle.css', // CSS output in `dist/static/css`
}),
...htmlPlugins, // Include dynamically generated HTML plugins
],
};