-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathwebpack.config.mjs
57 lines (55 loc) · 1.38 KB
/
webpack.config.mjs
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
// @ts-check
import HtmlWebpackPlugin from "html-webpack-plugin";
import path from "node:path";
/** @type {"development" | "production"} */
const NODE_ENV =
process.env.NODE_ENV === "production" ? "production" : "development";
const PROD = NODE_ENV === "production";
/** @type {import("webpack").Configuration} */
export default {
entry: { "build/bundle": ["./src/index.js"] },
output: {
publicPath: "/",
path: path.resolve("./public"),
filename: PROD ? "[name].[contenthash].js" : "[name].js",
chunkFilename: "[name].[id].js",
clean: true,
},
module: {
rules: [
{
test: /\.(svelte|svelte\.js)$/,
use: {
loader: "svelte-loader",
options: {
emitCss: false,
hotReload: !PROD,
compilerOptions: { dev: !PROD },
},
},
},
{
test: /\.m?js/,
resolve: { fullySpecified: false },
},
],
},
mode: NODE_ENV,
plugins: [
new HtmlWebpackPlugin({
templateContent: `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body></body>
</html>
`,
}),
],
stats: "errors-only",
devtool: PROD ? false : "source-map",
devServer: { hot: true, historyApiFallback: true },
};