forked from erikvullings/scenario-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rspack.config.ts
130 lines (124 loc) · 3.33 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
120
121
122
123
124
125
126
127
128
129
130
import { config } from 'dotenv';
import { resolve } from 'path';
import { Configuration } from '@rspack/cli';
import {
DefinePlugin,
HtmlRspackPlugin,
HotModuleReplacementPlugin,
SwcJsMinimizerRspackPlugin,
LightningCssMinimizerRspackPlugin,
} from '@rspack/core';
config();
const devMode = (process.env as any).NODE_ENV === 'development';
const isProduction = !devMode;
const outputPath = resolve(__dirname, devMode ? 'dist' : './docs');
const SERVER = process.env.SERVER;
// const publicPath = isProduction
// ? 'https://github.io/Maplibre GUI for population simulator/popsicle'
// : '';
const APP_PORT = 8339;
console.log(
`Running in ${
isProduction ? 'production' : 'development'
} mode, serving from ${SERVER}, output directed to ${outputPath}.`
);
const configuration: Configuration = {
experiments: {
css: true,
// asyncWebAssembly: true,
},
mode: isProduction ? 'production' : 'development',
entry: {
main: './src/app.ts',
},
devServer: {
port: APP_PORT,
},
devtool: 'source-map',
plugins: [
new DefinePlugin({
// 'process.env.NODE_ENV': "'development'",
// 'process.env.SERVER': isProduction
// ? `'${publicPath}'`
// : "'http://localhost:4545'",
}),
new HtmlRspackPlugin({
title: 'Scenario Spark',
publicPath: devMode ? undefined : 'https://tno.github.io/scenario-spark',
scriptLoading: 'defer',
minify: !devMode,
favicon: './src/favicon.ico',
meta: {
viewport: 'width=device-width, initial-scale=1',
'Content-Security-Policy': {
'http-equiv': 'Permissions-Policy',
content: 'interest-cohort=(), user-id=()',
},
'og:title': 'Scenario Spark',
'og:description':
'Generate consistent threat scenarios for your organisation.',
'og:url': 'https://tno.github.io/scenario-spark/',
'og:site_name': 'Scenario Spark',
'og:image:alt': 'Scenario Spark',
'og:image': './src/assets/logo.svg',
'og:image:type': 'image/svg',
'og:image:width': '200',
'og:image:height': '200',
},
}),
new HotModuleReplacementPlugin(),
new LightningCssMinimizerRspackPlugin({
removeUnusedLocalIdents: true,
// minimizerOptions: {}
}),
new SwcJsMinimizerRspackPlugin({
minimizerOptions: devMode
? {}
: {
compress: true,
minify: true,
// mangle: true,
},
}),
],
resolve: {
extensions: ['...', '.ts', '*.wasm', '*.csv', '*.json'], // "..." 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',
},
},
},
type: 'javascript/auto',
},
{
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',
},
],
},
output: {
filename: 'main.js',
// filename: '[id].bundle.js',
// publicPath,
path: outputPath,
},
};
export default configuration;