-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.config.js
More file actions
926 lines (909 loc) Β· 29.2 KB
/
webpack.config.js
File metadata and controls
926 lines (909 loc) Β· 29.2 KB
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
/*
* Copyright (c) 2021-2023 Datalayer, Inc.
*
* MIT License
*/
// @ts-nocheck - webpack config uses Node.js require.resolve which TS doesn't recognize
"use strict";
const path = require("path");
const webpack = require("webpack");
const miniSVGDataURI = require("mini-svg-data-uri");
const CopyPlugin = require("copy-webpack-plugin");
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
// Helper to resolve package paths in monorepo (hoisted node_modules)
/**
* @param {string} packageName
* @returns {string}
*/
const resolvePackage = (packageName) => {
try {
// First try to resolve package.json directly (works for most packages)
return path.dirname(require.resolve(`${packageName}/package.json`));
} catch {
// Fallback: resolve any subpath and extract package directory
// For packages with exports but no main/package.json export
try {
const resolved = require.resolve(packageName);
const parts = resolved.split(path.sep);
const nmIndex = parts.lastIndexOf("node_modules");
if (nmIndex === -1) return path.dirname(resolved);
// Handle scoped packages (@scope/pkg)
if (packageName.startsWith("@")) {
return parts.slice(0, nmIndex + 3).join(path.sep);
}
return parts.slice(0, nmIndex + 2).join(path.sep);
} catch {
// Last resort: walk up the directory tree to find the nearest
// ancestor node_modules (supports both simple repos and monorepos)
let dir = __dirname;
while (true) {
const candidate = path.join(dir, "node_modules", packageName);
if (require("fs").existsSync(candidate)) {
return candidate;
}
const parent = path.dirname(dir);
if (parent === dir) break; // reached filesystem root
dir = parent;
}
// Final fallback: assume local node_modules
return path.join(__dirname, "node_modules", packageName);
}
}
};
/** @typedef {import('webpack').Configuration} WebpackConfig **/
/** @type WebpackConfig */
const extensionConfig = {
target: "node", // VS Code extensions run in a Node.js-context π -> https://webpack.js.org/configuration/node/
mode: "none", // this leaves the source code as close as possible to the original (when packaging we set this to 'production')
entry: "./src/preload.ts", // CHANGED: Use preload.ts to force os module loading BEFORE any other code, π -> https://webpack.js.org/configuration/entry-context/
// Disable webpack's default polyfilling of __filename / __dirname.
// For target: "node", webpack's default replaces both with fake `/index.js`
// and `/` paths. That breaks @datalayer/core's NodeStorage, which uses
// `module.createRequire(__filename)` to load `keytar` at runtime β the
// fake path makes createRequire root the require at the filesystem root,
// where there is no `node_modules/keytar`. Setting these to `false`
// tells webpack to leave them alone, so Node fills in the real bundle
// path at runtime and createRequire resolves real node_modules. π https://webpack.js.org/configuration/node/
node: {
__filename: false,
__dirname: false,
},
output: {
// the bundle is stored in the 'dist' folder (check package.json), π -> https://webpack.js.org/configuration/output/
path: path.resolve(__dirname, "dist"),
filename: "extension.js",
libraryTarget: "commonjs2",
},
externals: {
vscode: "commonjs vscode", // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, π -> https://webpack.js.org/configuration/externals/
os: "commonjs os", // Node.js built-in - must be external to ensure require cache works correctly
zeromq: "commonjs zeromq", // zeromq has native bindings that must be excluded from webpack
"cmake-ts": "commonjs cmake-ts", // required by zeromq for loading native modules
"prebuild-install": "commonjs prebuild-install", // used by native modules, has os.platform() calls
ws: "commonjs ws", // WebSocket library with optional native bindings (bufferUtil), pulls in prebuild-install
bufferutil: "commonjs bufferutil", // Optional native module for ws
"utf-8-validate": "commonjs utf-8-validate", // Optional native module for ws
pyodide: "commonjs pyodide", // pyodide package is HUGE (~10MB+ WASM), must be external to avoid heap overflow during webpack bundling
"@github/keytar": "commonjs @github/keytar", // GitHub's keytar fork: ships prebuilt binaries for all platforms in a single multi-platform VSIX (no per-OS rebuild needed). Loaded first by @datalayer/core's NodeStorage.
// React packages must be EXTERNAL - they should NOT run in Node.js extension context
// React code with hooks causes "Invalid hook call" warnings when bundled into extension.js
react: "commonjs react",
"react-dom": "commonjs react-dom",
"@primer/react": "commonjs @primer/react", // Has CSS imports that fail in Node.js 22
// @datalayer packages are BUNDLED (not external) so webpack can handle their React dependencies
// When webpack encounters React imports in these packages, it externalizes them (because React is external above)
// This prevents Node.js from trying to load packages with CSS imports at runtime
// EXCEPTION: /tools exports must be external to avoid bundling dependencies with os.platform() calls
"@datalayer/jupyter-react/tools": "commonjs @datalayer/jupyter-react/tools",
"@datalayer/jupyter-lexical/lib/tools":
"commonjs @datalayer/jupyter-lexical/lib/tools",
"@jupyterlab/application": "commonjs @jupyterlab/application",
"@jupyterlab/notebook": "commonjs @jupyterlab/notebook",
"@jupyterlab/cells": "commonjs @jupyterlab/cells",
"@jupyterlab/completer": "commonjs @jupyterlab/completer",
"@lexical/react": "commonjs @lexical/react",
lexical: "commonjs lexical",
// modules added here also need to be added in the .vscodeignore file
},
resolve: {
// support reading TypeScript and JavaScript files, π -> https://github.com/TypeStrong/ts-loader
extensions: [".ts", ".js"],
},
module: {
rules: [
{
test: /\.css$/,
use: "null-loader", // Ignore CSS imports in extension context (Node.js 22 can't load CSS)
},
{
test: /\.(woff|woff2|eot|ttf|otf|svg|png|jpg|jpeg|gif)$/,
type: "asset/resource", // Handle font/image assets
},
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
loader: "ts-loader",
},
],
},
{
test: /\.(c|m)?js/,
resolve: {
fullySpecified: false,
},
},
// Ignore CSS files in extension bundle since they're not needed in Node.js context
{
test: /\.css$/,
use: "null-loader",
},
// Handle other assets that might be imported
{
test: /\.(png|jpg|jpeg|gif|svg|woff|woff2|eot|ttf|otf)$/,
use: "null-loader",
},
// Ignore Python wheel files (not needed in Node.js extension context)
{
test: /\.whl$/,
use: "null-loader",
},
// Ignore WASM files (not needed in Node.js extension context)
{
test: /\.wasm$/,
use: "null-loader",
},
// Python file loader (for Pyodide kernel in native notebooks)
{
test: /pyodide_kernel\.py$/,
type: "asset/source",
},
],
},
devtool: "nosources-source-map",
infrastructureLogging: {
level: "log", // enables logging required for problem matchers
},
};
// Webpack's `performance` hints assume a network round-trip and warn for
// any asset over 244 KiB. VS Code webviews instead load bundles from local
// disk via `vscode-webview-resource://`, so the network heuristic doesn't
// apply: a 5 MiB lazy chunk costs the same as a 200 KiB one. Disabling
// these hints removes noise from `npm run compile` without hiding real
// regressions β bundle-size tracking already happens through
// `npm run analyze` (treemap reports), which is the right tool for it.
const WEBVIEW_PERFORMANCE_HINTS = { hints: false };
const webviewConfig = {
target: "web",
// Use development mode when WEBVIEW_DEBUG=1 to preserve console.log and avoid minification
mode: process.env.WEBVIEW_DEBUG ? "development" : "production",
// Source map strategy:
// - Development (WEBVIEW_DEBUG=1): inline-source-map for easy debugging
// - Production (default): hidden-source-map generates .map files without bundle bloat
// Reference: https://github.com/microsoft/vscode/issues/145292#issuecomment-1072879043
devtool: process.env.WEBVIEW_DEBUG
? "inline-source-map"
: "hidden-source-map",
entry: "./webview/notebook/main.ts",
output: {
path: path.resolve(__dirname, "dist"),
filename: "webview.js",
},
performance: WEBVIEW_PERFORMANCE_HINTS,
optimization: {
// Disable code splitting to avoid RuntimeIdRuntimeModule conflicts with WASM
splitChunks: false,
runtimeChunk: false,
},
// Suppress warnings from external dependencies
ignoreWarnings: [
{
module: /node_modules\/@jupyterlite\/pyodide-kernel/,
message:
/Critical dependency: the request of a dependency is an expression/,
},
],
resolve: {
extensions: [".ts", ".tsx", ".js", ".jsx", ".json", ".svg"],
symlinks: true,
// Include root node_modules for hoisted packages in monorepo
// Walk up from project dir to find the nearest ancestor node_modules
// (works for both standalone repos and monorepos with arbitrary nesting)
modules: (() => {
const dirs = ["node_modules"];
let dir = __dirname;
while (true) {
const parent = path.dirname(dir);
if (parent === dir) break;
dir = parent;
const candidate = path.join(dir, "node_modules");
if (require("fs").existsSync(candidate)) {
dirs.push(candidate);
break;
}
}
return dirs;
})(),
fallback: {
process: require.resolve("process/browser"),
stream: false,
buffer: require.resolve("buffer/"),
assert: false,
},
// Deduplicate CodeMirror modules to prevent multiple instances
alias: {
// Force all imports to use the same instance
// Use resolvePackage helper to find packages in hoisted node_modules (monorepo)
react: resolvePackage("react"),
"react-dom": resolvePackage("react-dom"),
"@codemirror/state": resolvePackage("@codemirror/state"),
"@codemirror/view": resolvePackage("@codemirror/view"),
"@codemirror/language": resolvePackage("@codemirror/language"),
"@codemirror/commands": resolvePackage("@codemirror/commands"),
"@codemirror/search": resolvePackage("@codemirror/search"),
"@codemirror/autocomplete": resolvePackage("@codemirror/autocomplete"),
"@codemirror/lint": resolvePackage("@codemirror/lint"),
// Also deduplicate yjs to prevent synchronization issues
yjs: resolvePackage("yjs"),
"y-protocols": resolvePackage("y-protocols"),
"y-websocket": resolvePackage("y-websocket"),
},
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: {
loader: "ts-loader",
options: {
configFile: path.join(__dirname, "tsconfig.webview.json"),
experimentalWatchApi: true,
// transpileOnly enables hot-module-replacement
transpileOnly: true,
},
},
},
{ test: /\.raw\.css$/, type: "asset/source" },
{
test: /(?<!\.raw)\.css$/,
use: [require.resolve("style-loader"), require.resolve("css-loader")],
},
{
// Keep font files as emitted assets (no inlining), matching
// the working UI/jupyter-react behavior for MathJax CHTML fonts.
test: /\.(eot|ttf|woff2?)(\?v=\d+\.\d+\.\d+)?$/i,
type: "asset/resource",
},
{
test: /\.(jpe?g|png|gif|ico|map)(\?v=\d+\.\d+\.\d+)?$/i,
type: "asset/resource",
},
{
// In .css files, svg is loaded as a data URI.
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
issuer: /\.css$/,
type: "asset",
generator: {
dataUrl: (content) => miniSVGDataURI(content.toString()),
},
},
{
// In .ts and .tsx files (both of which compile to .js), svg files
// must be loaded as a raw string instead of data URIs.
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
issuer: /\.js$/,
type: "asset/source",
},
{
test: /\.(c|m)?js/,
resolve: {
fullySpecified: false,
},
},
// Ship the JupyterLite service worker.
{
resourceQuery: /text/,
type: "asset/resource",
generator: {
filename: "[name][ext]",
},
},
// Python file loader (for Pyodide kernel)
{
test: /pyodide_kernel\.py$/,
type: "asset/source",
},
// Worker JavaScript loader (for Pyodide worker)
{
test: /pyodideWorker\.worker\.js$/,
type: "asset/source",
},
// Rule for pyodide kernel wheel files
{
test: /\.whl$/,
type: "asset/resource",
generator: {
filename: "pypi/[name][ext]",
},
},
// Rule for other pyodide kernel resources
{
test: /pypi\/.*/,
type: "asset/resource",
generator: {
filename: "pypi/[name][ext][query]",
},
},
{
test: /pyodide-kernel-extension\/schema\/.*/,
type: "asset/resource",
generator: {
filename: "schema/[name][ext][query]",
},
},
],
},
plugins: [
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 1,
}),
new webpack.ProvidePlugin({
process: "process/browser",
}),
new CopyPlugin({
patterns: [
{
from: path.join(
resolvePackage("@vscode/codicons"),
"dist/codicon.css",
),
to: "codicon.css",
},
{
from: path.join(
resolvePackage("@vscode/codicons"),
"dist/codicon.ttf",
),
to: "codicon.ttf",
},
{
from: "webview/styles/vscode-completion-theme.css",
to: "vscode-completion-theme.css",
},
],
}),
],
};
// Config for Lexical editor webview
const lexicalWebviewConfig = {
...webviewConfig,
entry: {
main: "./webview/lexical/main.ts",
},
output: {
path: path.resolve(__dirname, "dist"),
filename: (pathData) => {
return pathData.chunk.name === "main"
? "lexicalWebview.js"
: "[name].lexical.js";
},
chunkFilename: "[name].lexical.chunk.js",
// This will be overridden at runtime by __webpack_public_path__
publicPath: "auto",
webassemblyModuleFilename: "[hash].module.wasm",
},
experiments: {
asyncWebAssembly: true,
},
optimization: {
// WASM async loading (loro-crdt) requires runtime chunk
// Creates lexical-runtime.js that must load BEFORE main bundle
runtimeChunk: {
name: "lexical-runtime",
},
splitChunks: false,
},
// Suppress warnings from external dependencies (inherited from webviewConfig)
ignoreWarnings: [
{
module: /node_modules\/@jupyterlite\/pyodide-kernel/,
message:
/Critical dependency: the request of a dependency is an expression/,
},
],
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: {
loader: "ts-loader",
options: {
configFile: path.join(__dirname, "tsconfig.webview.json"),
experimentalWatchApi: true,
transpileOnly: true,
},
},
},
{ test: /\.raw\.css$/, type: "asset/source" },
{
test: /(?<!\.raw)\.css$/,
use: [require.resolve("style-loader"), require.resolve("css-loader")],
},
{
// Keep font files as emitted assets (no inlining), matching
// the working UI/jupyter-react behavior for MathJax CHTML fonts.
test: /\.(eot|ttf|woff2?)(\?v=\d+\.\d+\.\d+)?$/i,
type: "asset/resource",
},
{
test: /\.(jpe?g|png|gif|ico|map)(\?v=\d+\.\d+\.\d+)?$/i,
type: "asset/resource",
},
{
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
issuer: /\.css$/,
type: "asset",
generator: {
dataUrl: (content) => miniSVGDataURI(content.toString()),
},
},
{
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
issuer: /\.js$/,
type: "asset/source",
},
{
test: /\.(c|m)?js/,
resolve: {
fullySpecified: false,
},
},
{
test: /\.wasm$/,
type: "webassembly/async",
},
// Python file loader (for Pyodide kernel)
{
test: /pyodide_kernel\.py$/,
type: "asset/source",
},
// Worker JavaScript loader (for Pyodide worker)
{
test: /pyodideWorker\.worker\.js$/,
type: "asset/source",
},
// Rule for pyodide kernel wheel files
{
test: /\.whl$/,
type: "asset/resource",
generator: {
filename: "pypi/[name][ext]",
},
},
// Rule for other pyodide kernel resources
{
test: /pypi\/.*/,
type: "asset/resource",
generator: {
filename: "pypi/[name][ext][query]",
},
},
{
test: /pyodide-kernel-extension\/schema\/.*/,
type: "asset/resource",
generator: {
filename: "schema/[name][ext][query]",
},
},
],
},
resolve: {
extensions: [".ts", ".tsx", ".js", ".jsx", ".json", ".svg", ".wasm"],
symlinks: true,
fallback: {
process: require.resolve("process/browser"),
stream: false,
buffer: require.resolve("buffer/"),
assert: false,
},
// Deduplicate CodeMirror modules to prevent multiple instances
alias: {
// Force all imports to use the same instance
// Use resolvePackage helper to find packages in hoisted node_modules (monorepo)
react: resolvePackage("react"),
"react-dom": resolvePackage("react-dom"),
"@codemirror/state": resolvePackage("@codemirror/state"),
"@codemirror/view": resolvePackage("@codemirror/view"),
"@codemirror/language": resolvePackage("@codemirror/language"),
"@codemirror/commands": resolvePackage("@codemirror/commands"),
"@codemirror/search": resolvePackage("@codemirror/search"),
"@codemirror/autocomplete": resolvePackage("@codemirror/autocomplete"),
"@codemirror/lint": resolvePackage("@codemirror/lint"),
// Also deduplicate yjs to prevent synchronization issues
yjs: resolvePackage("yjs"),
"y-protocols": resolvePackage("y-protocols"),
"y-websocket": resolvePackage("y-websocket"),
},
},
plugins: [...webviewConfig.plugins],
};
// Config for Primer Showcase webview
const showcaseWebviewConfig = {
target: "web",
mode: "none",
devtool: "inline-source-map",
entry: "./webview/showcase/index.tsx",
output: {
path: path.resolve(__dirname, "dist"),
filename: "showcase.js",
},
resolve: {
extensions: [".ts", ".tsx", ".js", ".jsx", ".json"],
symlinks: true,
fallback: {
process: require.resolve("process/browser"),
buffer: require.resolve("buffer/"),
},
alias: {
// Use resolvePackage helper to find packages in hoisted node_modules (monorepo)
react: resolvePackage("react"),
"react-dom": resolvePackage("react-dom"),
},
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: {
loader: "ts-loader",
options: {
configFile: path.join(__dirname, "tsconfig.webview.json"),
experimentalWatchApi: true,
transpileOnly: true,
},
},
},
{
test: /\.css$/,
use: [require.resolve("style-loader"), require.resolve("css-loader")],
},
{
test: /\.(c|m)?js/,
resolve: {
fullySpecified: false,
},
},
],
},
plugins: [
new webpack.ProvidePlugin({
process: "process/browser",
}),
],
};
// Config for Datalayer Agent Chat sidebar webview.
// Inherits from webviewConfig for full CSS/asset/polyfill support.
// Code splitting is ENABLED (no LimitChunkCountPlugin) so React.lazy()
// can async-load the heavy Chat component into a separate chunk, keeping
// the entry bundle lightweight enough for the webview to evaluate.
const agentChatWebviewConfig = {
...webviewConfig,
entry: "./webview/agentChat/index.tsx",
output: {
path: path.resolve(__dirname, "dist"),
filename: "agentChat.js",
chunkFilename: "agentChat.[name].chunk.js",
// "auto" derives the public path from the <script src="..."> URI,
// which in a VS Code webview is a vscode-webview-resource: URI.
// Async chunks loaded by webpack will resolve relative to that.
publicPath: "auto",
},
optimization: {
// Allow code splitting β the Chat component is loaded via React.lazy.
// Do NOT set `splitChunks: false` here: it causes webpack to stop
// emitting the main `agentChat.js` entry bundle while still producing
// all the async chunks, leaving the webview to 404 on load.
splitChunks: {
chunks: "async",
},
runtimeChunk: false,
},
plugins: webviewConfig.plugins.filter((plugin) => {
// Inherit every webviewConfig plugin so future additions (e.g. extra
// ProvidePlugin entries) propagate automatically and don't drift, but
// drop the two that don't belong here:
//
// - `LimitChunkCountPlugin` is what disables code splitting; we MUST
// keep splitting on so `React.lazy(() => import('Chat'))` works.
// - `CopyPlugin` emits codicon assets to `dist/`. The main webview
// build already does this (same `dist/` target), so re-running it
// here would just rewrite the same files twice per build.
const ctorName = plugin?.constructor?.name;
return ctorName !== "LimitChunkCountPlugin" && ctorName !== "CopyPlugin";
}),
// `performance` is inherited from `webviewConfig` (hints disabled β
// see comment on `WEBVIEW_PERFORMANCE_HINTS`).
};
// Config for ag-ui example webview
const aguiExampleConfig = {
target: "web",
mode: "none",
devtool: "inline-source-map",
entry: "./webview/datalayer-core/AgUIExample.tsx",
output: {
path: path.resolve(__dirname, "dist"),
filename: "aguiExample.js",
},
resolve: {
extensions: [".ts", ".tsx", ".js", ".jsx", ".json"],
symlinks: true,
fallback: {
process: require.resolve("process/browser"),
buffer: require.resolve("buffer/"),
stream: false,
},
alias: {
// Use resolvePackage helper to find packages in hoisted node_modules (monorepo)
react: resolvePackage("react"),
"react-dom": resolvePackage("react-dom"),
},
},
ignoreWarnings: [
{
module: /node_modules\/@jupyterlite\/pyodide-kernel/,
message:
/Critical dependency: the request of a dependency is an expression/,
},
],
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: {
loader: "ts-loader",
options: {
configFile: path.join(__dirname, "tsconfig.webview.json"),
experimentalWatchApi: true,
transpileOnly: true,
},
},
},
{ test: /\.raw\.css$/, type: "asset/source" },
{
test: /(?<!\.raw)\.css$/,
use: [require.resolve("style-loader"), require.resolve("css-loader")],
},
{
test: /\.svg/,
type: "asset/inline",
generator: {
dataUrl: (content) => miniSVGDataURI(content.toString()),
},
},
{
test: /\.(png|jpg|jpeg|gif|woff|woff2|eot|ttf|otf)$/,
type: "asset/resource",
},
{
test: /\.(c|m)?js/,
resolve: {
fullySpecified: false,
},
},
// Rule for pyodide kernel wheel files
{
test: /\.whl$/,
type: "asset/resource",
generator: {
filename: "pypi/[name][ext]",
},
},
// Rule for other pyodide kernel resources
{
test: /pypi\/.*/,
type: "asset/resource",
generator: {
filename: "pypi/[name][ext][query]",
},
},
{
test: /pyodide-kernel-extension\/schema\/.*/,
type: "asset/resource",
generator: {
filename: "schema/[name][ext][query]",
},
},
],
},
plugins: [
new webpack.ProvidePlugin({
process: "process/browser",
}),
],
};
// Config for Datasource Dialog webview
const datasourceDialogConfig = {
target: "web",
mode: "production", // Enable webpack production optimizations
devtool: process.env.WEBVIEW_DEBUG
? "inline-source-map"
: "hidden-source-map",
entry: "./webview/datasource/main.tsx",
output: {
path: path.resolve(__dirname, "dist"),
filename: "datasourceDialog.js",
},
performance: WEBVIEW_PERFORMANCE_HINTS,
resolve: {
extensions: [".ts", ".tsx", ".js", ".jsx", ".json", ".svg"],
symlinks: true,
fallback: {
process: require.resolve("process/browser"),
buffer: require.resolve("buffer/"),
stream: require.resolve("stream-browserify"),
// Disable node modules not needed in browser
fs: false,
path: false,
crypto: false,
},
alias: {
// Use resolvePackage helper to find packages in hoisted node_modules (monorepo)
react: resolvePackage("react"),
"react-dom": resolvePackage("react-dom"),
// Stub out react-router-dom since we don't use navigation in webview
"react-router-dom": false,
},
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: {
loader: "ts-loader",
options: {
configFile: path.join(__dirname, "tsconfig.webview.json"),
experimentalWatchApi: true,
transpileOnly: true,
},
},
},
{
test: /\.css$/,
use: [require.resolve("style-loader"), require.resolve("css-loader")],
},
{
test: /\.svg$/,
type: "asset/inline",
},
{
test: /\.(c|m)?js/,
resolve: {
fullySpecified: false,
},
},
],
},
plugins: [
new webpack.ProvidePlugin({
process: "process/browser",
}),
],
};
// Config for Datasource Edit Dialog webview
const datasourceEditDialogConfig = {
target: "web",
mode: "production", // Enable webpack production optimizations
devtool: process.env.WEBVIEW_DEBUG
? "inline-source-map"
: "hidden-source-map",
entry: "./webview/datasource/editMain.tsx",
output: {
path: path.resolve(__dirname, "dist"),
filename: "datasourceEditDialog.js",
},
performance: WEBVIEW_PERFORMANCE_HINTS,
resolve: {
extensions: [".ts", ".tsx", ".js", ".jsx", ".json", ".svg"],
symlinks: true,
fallback: {
process: require.resolve("process/browser"),
buffer: require.resolve("buffer/"),
stream: require.resolve("stream-browserify"),
// Disable node modules not needed in browser
fs: false,
path: false,
crypto: false,
},
alias: {
// Use resolvePackage helper to find packages in hoisted node_modules (monorepo)
react: resolvePackage("react"),
"react-dom": resolvePackage("react-dom"),
// Stub out react-router-dom since we don't use navigation in webview
"react-router-dom": false,
},
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: {
loader: "ts-loader",
options: {
configFile: path.join(__dirname, "tsconfig.webview.json"),
experimentalWatchApi: true,
transpileOnly: true,
},
},
},
{
test: /\.css$/,
use: [require.resolve("style-loader"), require.resolve("css-loader")],
},
{
test: /\.svg$/,
type: "asset/inline",
},
{
test: /\.(c|m)?js/,
resolve: {
fullySpecified: false,
},
},
],
},
plugins: [
new webpack.ProvidePlugin({
process: "process/browser",
}),
],
};
// When ANALYZE=true, add BundleAnalyzerPlugin to each config.
// Each config gets its own report file to avoid overwriting.
const configs = [
extensionConfig,
webviewConfig,
lexicalWebviewConfig,
showcaseWebviewConfig,
datasourceDialogConfig,
datasourceEditDialogConfig,
agentChatWebviewConfig,
// aguiExampleConfig, // Commented out - file doesn't exist
];
if (process.env.ANALYZE === "true") {
const configNames = [
"extension",
"webview",
"lexical",
"showcase",
"datasource",
"datasource-edit",
"agentChat",
];
configs.forEach((config, index) => {
const name = configNames[index] || `config-${index}`;
config.plugins = config.plugins || [];
config.plugins.push(
new BundleAnalyzerPlugin({
analyzerMode: "static",
reportFilename: path.resolve(
__dirname,
`dist/bundle-report-${name}.html`,
),
openAnalyzer: false,
generateStatsFile: true,
statsFilename: path.resolve(
__dirname,
`dist/bundle-stats-${name}.json`,
),
}),
);
});
}
module.exports = configs;