forked from google/neuroglancer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
153 lines (150 loc) · 4.66 KB
/
webpack.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import path from "node:path";
import { EsbuildPlugin } from "esbuild-loader";
import HtmlWebpackPlugin from "html-webpack-plugin";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import webpack from "webpack";
import StartupChunkDependenciesPlugin from "webpack/lib/runtime/StartupChunkDependenciesPlugin.js";
import { normalizeConfigurationWithDefine } from "./build_tools/webpack/configuration_with_define.js";
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",
},
minimizer: [
new EsbuildPlugin({
target: "es2020",
format: "esm",
css: true,
}),
],
},
devtool: "source-map",
module: {
rules: [
// Needed to support Neuroglancer TypeScript sources.
{
test: /\.tsx?$/,
loader: "esbuild-loader",
options: {
// Needed to ensure `import.meta.url` is available.
target: "es2020",
},
},
{
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]",
},
},
// Necessary to handle CSS files.
{
test: /\.css$/,
use: [
{
loader:
mode === "production"
? MiniCssExtractPlugin.loader
: "style-loader",
},
{ loader: "css-loader" },
],
},
],
},
devServer: {
client: {
overlay: {
// Prevent intrusive notification spam.
runtimeErrors: false,
},
},
hot: false,
},
plugins: [
// Fixes esm output with splitChunks
// https://github.com/webpack/webpack/pull/17015/files
new StartupChunkDependenciesPlugin({
chunkLoading: "import",
asyncChunkLoading: true,
}),
new webpack.ProgressPlugin(),
...(mode === "production"
? [new MiniCssExtractPlugin({ filename: "[name].[chunkhash].css" })]
: []),
new HtmlWebpackPlugin({
title: "Neuroglancer",
scriptLoading: "module",
}),
],
output: {
path: path.resolve(import.meta.dirname, "dist", "client"),
filename: "[name].[chunkhash].js",
chunkFilename: "[name].[contenthash].js",
chunkLoading: "import",
workerChunkLoading: "import",
chunkFormat: "module",
asyncChunks: true,
module: true,
clean: true,
},
target: ["es2020", "web"],
experiments: {
outputModule: true,
},
// Additional defines, to be added via `webpack.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'),
},
};
return env.NEUROGLANCER_CLI
? config
: normalizeConfigurationWithDefine(config);
};