forked from google/neuroglancer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rspack.config.js
127 lines (124 loc) · 3.74 KB
/
rspack.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import path from "node:path";
import { HtmlRspackPlugin, ProgressPlugin } from "@rspack/core";
import { normalizeConfigurationWithDefine } from "./build_tools/rspack/configuration_with_define.js";
import packageJson from "./package.json";
export default (env, args) => {
const mode = args.mode === "production" ? "production" : "development";
const config = {
mode,
context: import.meta.dirname,
entry: {
main: "./src/main.bundle.js",
},
performance: {
// Avoid unhelpful warnings due to large bundles.
maxAssetSize: 3 * 1024 * 1024,
maxEntrypointSize: 3 * 1024 * 1024,
},
optimization: {
splitChunks: {
chunks: "all",
},
},
devtool: "source-map",
module: {
rules: [
// Needed to support Neuroglancer TypeScript sources.
{
test: /\.tsx?$/,
loader: "builtin:swc-loader",
options: {
jsc: {
parser: {
syntax: "typescript",
decorators: true,
},
},
env: {
targets: packageJson.browserslist,
},
},
type: "javascript/auto",
},
{
test: /\.wasm$/,
generator: {
filename: "[name].[contenthash][ext]",
},
},
// Needed for .svg?raw imports used for embedding icons.
{
resourceQuery: /raw/,
type: "asset/source",
},
// Needed for .html assets used for auth redirect pages for the
// brainmaps and bossDB data sources.
{
test: /(bossauth|google_oauth2_redirect)\.html$/,
type: "asset/resource",
generator: {
// Filename must be preserved since exact redirect URLs must be allowlisted.
filename: "[name][ext]",
},
},
],
},
devServer: {
client: {
overlay: {
// Prevent intrusive notification spam.
runtimeErrors: false,
},
},
hot: false,
},
plugins: [
new ProgressPlugin(),
new HtmlRspackPlugin({
title: "neuroglancer",
}),
],
output: {
path: path.resolve(import.meta.dirname, "dist", "client"),
filename: "[name].[chunkhash].js",
chunkFilename: "[name].[contenthash].js",
asyncChunks: true,
clean: true,
},
target: ["web", "browserslist"],
experiments: {
css: true,
},
// Additional defines, to be added via `DefinePlugin`. This is not a
// standard webpack configuration property, but is handled specially by
// `normalizeConfigurationWithDefine`.
define: {
// This is the default client ID used for the hosted neuroglancer.
// In addition to the hosted neuroglancer origin, it is valid for
// the origins:
//
// localhost:8000
// 127.0.0.1:8000
// localhost:8080
// 127.0.0.1:8080
//
// To deploy to a different origin, you will need to generate your
// own client ID from on the Google Developer Console and substitute
// it in.
NEUROGLANCER_BRAINMAPS_CLIENT_ID: JSON.stringify(
"639403125587-4k5hgdfumtrvur8v48e3pr7oo91d765k.apps.googleusercontent.com",
),
// NEUROGLANCER_CREDIT_LINK: JSON.stringify({url: '...', text: '...'}),
// NEUROGLANCER_DEFAULT_STATE_FRAGMENT: JSON.stringify('gs://bucket/state.json'),
// NEUROGLANCER_SHOW_LAYER_BAR_EXTRA_BUTTONS: true,
// NEUROGLANCER_SHOW_OBJECT_SELECTION_TOOLTIP: true
// NEUROGLANCER_GOOGLE_TAG_MANAGER: JSON.stringify('GTM-XXXXXX'),
},
watchOptions: {
ignored: /node_modules/,
},
};
return env.NEUROGLANCER_CLI
? config
: normalizeConfigurationWithDefine(config);
};