Browse Source

Merge pull request #4810 from RaananW/module-changes

Module changes
David Catuhe 7 năm trước cách đây
mục cha
commit
baf2e697f3

+ 2 - 1
Tools/Gulp/gulpfile.js

@@ -455,7 +455,6 @@ var buildExternalLibrary = function (library, settings, watch) {
                     if (!out.minified) {
                         wpConfig.mode = "development";
                     }
-                    console.log(wpConfig)
                     let wpBuild = webpackStream(wpConfig, webpack);
 
                     //shoud dtsBundle create the declaration?
@@ -558,6 +557,8 @@ var buildExternalLibrary = function (library, settings, watch) {
                                 if (err) throw err;
                                 var newData = processDeclaration(data, settings.build.processDeclaration);
                                 fs.writeFile(fileLocation.replace('.module', ''), newData);
+                                //legacy module support
+                                fs.writeFile(fileLocation, data + "\n" + newData);
                             });
                         }
                     });

+ 7 - 0
Tools/Gulp/processViewerDeclaration.js

@@ -59,7 +59,14 @@ module.exports = function (data, options) {
 
     str = str.replace(/export {(.*)};/g, '');
 
+    str = str.replace(/import (.*);/g, "");
+
     str = str.split("\n").filter(line => line.trim()).filter(line => line.indexOf("export * from") === -1).join("\n");
 
+    //empty declare regex
+    let emptyDeclareRegexp = new RegExp("declare module " + options.moduleName + " {\n}", "g");
+
+    str = str.replace(emptyDeclareRegexp, "");
+
     return str;
 }

+ 2 - 1
Tools/Publisher/index.js

@@ -51,7 +51,8 @@ let packages = [
         required: [
             basePath + '/viewer/readme.md',
             basePath + '/viewer/package.json',
-            basePath + '/viewer/babylon.viewer.js'
+            basePath + '/viewer/babylon.viewer.js',
+            basePath + '/viewer/babylon.viewer.max.js'
         ]
     },
     {

+ 15 - 0
gui/src/legacy.ts

@@ -0,0 +1,15 @@
+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;
+}
+
+export * from "./index";

+ 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'),

+ 1 - 1
inspector/src/Inspector.ts

@@ -54,7 +54,7 @@ export class Inspector {
 
         import("babylonjs-gui").then(GUI => {
             // Load GUI library if not already done
-            if (!GUI || (<Object>GUI).hasOwnProperty("default")) {
+            if (!GUI || (typeof GUI !== "undefined" && Object.keys(GUI).indexOf("default") !== -1)) {
                 Tools.LoadScript("https://preview.babylonjs.com/gui/babylon.gui.min.js", () => {
                     Inspector.GUIObject = (<any>BABYLON).GUI;
                     this.onGUILoaded.notifyObservers(Inspector.GUIObject);

+ 15 - 0
inspector/src/legacy.ts

@@ -0,0 +1,15 @@
+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;
+}
+
+export * from "./index";

+ 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,