Skip to content

Commit 0211cce

Browse files
authored
Inspector v2: Playground integration fixes (#16753)
From what I can tell, Playground is setup such that the site itself is bundled, and separately it uses the babylonjs umd bundle for running the actual user code in the Playground. Some the Playground website features themselves seem to use @dev/core, and from what I can tell this is a different copy of the code from core. For the inspector-v2 integration, it was effectively also getting a copy of code from core, so the actual classes inspector v2 was looking at were not the same as the ones coming from the Playground user code (e.g. the objects had different prototype chains). I updated the Playground webpack config to externalize any `import { blah } from "core/blah"` to BABYLON for the inspector-v2 and this fixes the problem. That said, it's unclear to me why we don't do this for other features. Why does the Playground site ever need a separate copy of things from core rather than just getting them through the UMD bundle (e.g. BABYLON)? I tried to change it so that all @dev/core and core imports are externalized to BABYLON, but this broke all kinds of things. I don't really understand why, so for now I'm just limiting the externalization to inspector-v2 (e.g. don't change anything was already being packed before adding inspector-v2 to the mix). I'll discuss more with Raanan when he's back. Also added a VSCode task dependency on inspector-v2 watch to make sure inspector v2 code changes are reflected in Playground.
1 parent 338237b commit 0211cce

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

.vscode/tasks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@
255255
"label": "Playground Serve (Dev)",
256256
"type": "shell",
257257
"command": "npm",
258-
"dependsOn": "CDN Serve and watch (Dev)",
258+
"dependsOn": ["CDN Serve and watch (Dev)", "Watch Inspector v2"],
259259
"runOptions": {
260260
"instanceLimit": 1
261261
},

packages/tools/playground/webpack.config.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,24 @@ module.exports = (env) => {
2525
loaders: path.resolve("../../dev/loaders/dist"),
2626
},
2727
},
28-
externals: {
29-
"@dev/core": "BABYLON",
30-
},
28+
externals: [
29+
function ({ context, request }, callback) {
30+
if (/^@dev\/core$/.test(request)) {
31+
return callback(null, "BABYLON");
32+
}
33+
34+
if (context.includes("inspector-v2")) {
35+
if (/^core\//.test(request)) {
36+
return callback(null, "BABYLON");
37+
} else if (/^loaders\//.test(request)) {
38+
return callback(null, "BABYLON");
39+
}
40+
}
41+
42+
// Continue without externalizing the import
43+
callback();
44+
},
45+
],
3146
module: {
3247
rules: webpackTools.getRules({
3348
sideEffects: true,

0 commit comments

Comments
 (0)