generated from AhsanAyaz/reveal-multi-slides-template
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathwebpack.config.js
110 lines (106 loc) · 3.06 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
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ESLintPlugin = require('eslint-webpack-plugin');
const fs = require('fs');
const BASE_HREF = 'angular-in-90ish';
// Function to generate HtmlWebpackPlugin instances for each HTML file
function generateHtmlPlugins(templateDir) {
const templateFiles = fs.readdirSync(path.resolve(__dirname, templateDir));
return templateFiles
.filter((fileName) => fileName.endsWith('html'))
.map((item) => {
const parts = item.split('.');
const name = parts[0];
const extension = parts[1];
return new HtmlWebpackPlugin({
filename: `${name}.html`,
template: path.resolve(
__dirname,
`${templateDir}/${name}.${extension}`
),
base: process.env.NODE_ENV !== 'production' ? '/' : `/${BASE_HREF}/`,
inject: true,
minify: false,
});
});
}
const htmlPlugins = generateHtmlPlugins('./content');
module.exports = {
entry: './js/slides.js',
output: {
filename: 'bundle.[contenthash].js',
path: path.resolve(
__dirname,
process.env.NODE_ENV === 'production' ? `dist/${BASE_HREF}` : 'dist'
),
},
mode: 'development', // Change to 'production' when ready to deploy
devtool: 'source-map',
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
template: './index.html',
inject: false,
minify: false,
}),
...htmlPlugins,
new MiniCssExtractPlugin({
filename: 'styles/[name].[contenthash].css',
}),
new CopyWebpackPlugin({
patterns: [
{ from: 'content', to: 'content' },
{ from: 'data', to: 'data' },
{ from: 'main.js', to: 'main.js' },
{ from: 'profiles', to: 'profiles' },
{ from: 'assets', to: 'assets' },
],
}),
new ESLintPlugin(),
],
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: 'babel-loader',
},
{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader',
'sass-loader',
],
},
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
},
{
test: /\.(png|jpeg|jpg|gif|svg)$/i,
type: 'asset/resource',
},
],
},
optimization: {
minimize: true,
minimizer: [new TerserPlugin(), new CssMinimizerPlugin()],
},
devServer: {
static: {
directory: path.join(__dirname, 'dist'),
watch: true,
},
watchFiles: ['content/**/*', 'css/**/*', 'profiles/*'],
open: true,
port: 8000,
hot: true,
},
};