-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathwebpack.config.js
More file actions
142 lines (140 loc) · 3.3 KB
/
webpack.config.js
File metadata and controls
142 lines (140 loc) · 3.3 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
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
import path from "path";
import { fileURLToPath } from "url";
import HtmlWebpackPlugin from "html-webpack-plugin";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import CopyWebpackPlugin from "copy-webpack-plugin";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
export default {
entry: {
login: "./src/js/login.js",
index: "./src/js/index.js",
courses: "./src/js/courses.js",
course: "./src/js/course.js",
lesson: "./src/js/lesson.js",
editor: "./src/js/editor.js",
},
mode: "development",
output: {
path: path.resolve(__dirname, "public"),
filename: "js/[name].js",
assetModuleFilename: "imgs/[hash][ext][query]",
clean: true,
publicPath: "/",
},
module: {
rules: [
{
test: /\.css$/i,
use: [
MiniCssExtractPlugin.loader,
"css-loader",
"postcss-loader",
],
},
{
test: /\.(png|jpe?g|gif|svg|webp)$/i,
type: "asset/resource", // emits a separate file and exports the URL
},
],
},
devServer: {
static: {
directory: path.join(__dirname, "public"),
},
compress: true,
port: 5500, // you can change this port
open: true, // auto-opens the browser
hot: true, // enables hot module replacement
liveReload: true, // fallback auto-reload if HMR fails
historyApiFallback: {
rewrites: [
{
from: /^\/course\/[^\/]+\/section-[^\/]+\/lesson-[^\/]+$/, // /course/ANYTHING/section-ANYTHING/lesson-ANYTHING
to: "/pages/lesson.html",
},
{
from: /^\/course\/[^\/]+$/, // matches /course/anything
to: "/pages/course.html", // serve course/index.html
},
{
from: /^\/([^\/]+)$/, // matches /something
to: (context) => `/pages/${context.match[1]}.html`,
},
{
from: /^\/$/, // matches exactly "/"
to: "/pages/index.html",
},
],
},
},
plugins: [
new MiniCssExtractPlugin({
filename: "css/[name].css",
}),
new CopyWebpackPlugin({
patterns: [
{
from: "src/netlify.toml", // where you put the _redirects file
to: "", // output it at the root of /public
},
{
from: "src/data/",
to: "data",
},
{
from: "src/imgs/",
to: "imgs",
},
{
from: "src/markdown/",
to: "markdown",
},
{
from: "src/robots.txt",
to: "",
},
{
from: "src/sitemap.xml",
to: "",
},
],
}),
new HtmlWebpackPlugin({
template: "./src/pages/index.html",
filename: "pages/index.html",
chunks: ["index"],
favicon: "./src/imgs/logo.png",
}),
new HtmlWebpackPlugin({
template: "./src/pages/login.html",
filename: "pages/login.html",
chunks: ["login"],
favicon: "./src/imgs/logo.png",
}),
new HtmlWebpackPlugin({
template: "./src/pages/editor.html",
filename: "pages/editor.html",
chunks: ["editor"],
favicon: "./src/imgs/logo.png",
}),
new HtmlWebpackPlugin({
template: "./src/pages/courses.html",
filename: "pages/courses.html",
chunks: ["courses"],
favicon: "./src/imgs/logo.png",
}),
new HtmlWebpackPlugin({
template: "./src/pages/course.html",
filename: "pages/course.html",
chunks: ["course"],
favicon: "./src/imgs/logo.png",
}),
new HtmlWebpackPlugin({
template: "./src/pages/lesson.html",
filename: "pages/lesson.html",
chunks: ["lesson"],
favicon: "./src/imgs/logo.png",
}),
],
};