ソースを参照

Legacy support for UMD - global namespace is being populated.

Raanan Weber 7 年 前
コミット
3eb3496fe8
4 ファイル変更29 行追加3 行削除
  1. 13 0
      gui/src/legacy.ts
  2. 1 1
      gui/webpack.config.js
  3. 13 0
      inspector/src/legacy.ts
  4. 2 2
      inspector/webpack.config.js

+ 13 - 0
gui/src/legacy.ts

@@ -0,0 +1,13 @@
+import * as GUI from "./index";
+
+/**
+ * Legacy support, defining window.BABYLON.GUI (global variable).
+ * 
+ * This is the entry point for the UMD module. 
+ * The entry point for a future ESM package should be index.ts
+ */
+var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
+if (typeof globalObject !== "undefined") {
+    (<any>globalObject).BABYLON = (<any>globalObject).BABYLON || {};
+    (<any>globalObject).BABYLON.GUI = GUI;
+}

+ 1 - 1
gui/webpack.config.js

@@ -6,7 +6,7 @@ const CleanWebpackPlugin = require('clean-webpack-plugin');
 module.exports = {
     context: __dirname,
     entry: {
-        'babylonjs-gui': path.resolve(__dirname, './src/index.ts'),
+        'babylonjs-gui': path.resolve(__dirname, './src/legacy.ts'),
     },
     output: {
         path: path.resolve(__dirname, '../dist/preview release/gui'),

+ 13 - 0
inspector/src/legacy.ts

@@ -0,0 +1,13 @@
+import * as INSPECTOR from "./index";
+
+/**
+ * Legacy support, defining window.INSPECTOR (global variable).
+ * 
+ * This is the entry point for the UMD module. 
+ * The entry point for a future ESM package should be index.ts
+ */
+
+var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
+if (typeof globalObject !== "undefined") {
+    (<any>globalObject).INSPECTOR = INSPECTOR;
+}

+ 2 - 2
inspector/webpack.config.js

@@ -7,7 +7,7 @@ const CleanWebpackPlugin = require('clean-webpack-plugin');
 module.exports = {
     context: __dirname,
     entry: {
-        'babylonjs-inspector': path.resolve(__dirname, './src/index.ts'),
+        'babylonjs-inspector': path.resolve(__dirname, './src/legacy.ts'),
     },
     output: {
         path: path.resolve(__dirname, '../dist/preview release/inspector'),
@@ -69,7 +69,7 @@ module.exports = {
             ]
         }]
     },
-    mode: "production",
+    mode: "development",
     devServer: {
         contentBase: path.join(__dirname, "dist"),
         compress: false,