forked from DRIVER-EU/lessons-learned-framework
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rspack.config.ts
119 lines (113 loc) · 3.21 KB
/
rspack.config.ts
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
import { config } from "dotenv";
import { resolve } from "path";
import { Configuration } from "@rspack/cli";
import {
DefinePlugin,
HtmlRspackPlugin,
HotModuleReplacementPlugin,
SwcCssMinimizerRspackPlugin,
SwcJsMinimizerRspackPlugin,
} from "@rspack/core";
config();
// const rspack = require('@rspack/core');
const devMode = process.env.NODE_ENV === "development";
const outputPath = resolve(__dirname, devMode ? "dist" : "public");
const mode = devMode ? "development" : "production";
const serverURL = devMode ? process.env.SERVER_URL : "/api/v1";
console.log(`Working in ${mode} mode, server URL ${serverURL}.`);
const configuration: Configuration = {
mode,
entry: {
main: "./src/app.ts",
},
devServer: {
headers: [
{
key: "Content-Security-Policy",
value: "frame-ancestors 'self' http://localhost:8765;",
},
],
port: 1234,
},
plugins: [
new DefinePlugin({
NODE_ENV: "'development'",
SERVER_URL: `"${serverURL}"`,
API_SERVER: `"${process.env.SERVER || ""}"`,
}),
new HtmlRspackPlugin({
title: "Lessons-Learned Library (L3)",
publicPath: devMode ? undefined : undefined,
scriptLoading: "defer",
minify: !devMode,
favicon: "./src/favicon.ico",
meta: {
viewport: "width=device-width, initial-scale=1",
// csp: {
// "http-equiv": "Content-Security-Policy",
// content:
// "default-src 'self'; img-src https://*; child-src 'none'; frame-ancestors '*'",
// },
// "http-equiv": "Content-Security-Policy",
// content:
// "default-src 'self'; img-src https://*; child-src 'none'; frame-ancestors '*'",
"og:title": "Lessons-Learned Library",
"og:description":
"Welke ervaringen heb je opgedaan tijdens het afhandelen van een incident of crisis, en welke lessen wil je delen met je collega's.",
"og:url": "https://github.com/DRIVER-EU/lessons-learned-framework",
"og:site_name": "Lessons-Learned Library",
"og:image:alt": "Lessons-Learned Library",
"og:image": "./src/assets/logo.svg",
"og:image:type": "image/svg",
"og:image:width": "200",
"og:image:height": "200",
},
}),
new HotModuleReplacementPlugin(),
new SwcCssMinimizerRspackPlugin(),
new SwcJsMinimizerRspackPlugin({
compress: !devMode,
mangle: !devMode,
}),
],
resolve: {
extensions: ["...", ".ts"], // "..." means to extend from the default extensions
},
module: {
rules: [
{
test: /\.ts$/,
exclude: /[\\/]node_modules[\\/]/,
loader: "builtin:swc-loader",
options: {
sourceMap: true,
jsc: {
parser: {
syntax: "typescript",
},
},
},
},
{
test: /\.(png|svg|jpg|jpeg|gif|webp)$/i,
type: "asset/resource",
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/i,
type: "asset/resource",
},
{
test: /^BUILD_ID$/,
type: "asset/source",
},
],
},
optimization: {
minimize: !devMode,
},
output: {
filename: "main.js",
path: outputPath,
},
};
export = configuration;