Browse Source

Build es6 inspector

sebavan 6 years ago
parent
commit
142f9dd47f

+ 23 - 18
Tools/Config/config.js

@@ -1,4 +1,5 @@
 const path = require("path");
+const fs = require("fs-extra");
 
 const config = require("./config.json");
 const configFolder = __dirname;
@@ -41,23 +42,8 @@ config.modules.map(function(module) {
         path.join(rootFolder, settings.build.packageJSON) : 
         path.join(distDirectory, 'package.json');
 
-    const tsConfig = require(tsConfigPath);
-    const srcDirectory = path.resolve(mainDirectory, tsConfig.compilerOptions.rootDir);
-
-    const shaderGlob = srcDirectory + "/**/*.fx";
-    const shaderTSGlob = srcDirectory + "/**/*.fx.ts";
-
-    for (let library of settings.libraries) {
-        const entryPath = path.join(srcDirectory, library.entry);
-
-        library.computed = {
-            entryPath
-        };
-    }
-
     settings.computed = {
         mainDirectory,
-        srcDirectory,
         distDirectory,
         localDevES6Directory,
         localDevUMDDirectory,
@@ -66,9 +52,28 @@ config.modules.map(function(module) {
         packageES6Directory,
         webpackConfigPath,
         tsConfigPath,
-        packageJSONPath,
-        shaderGlob,
-        shaderTSGlob
+        packageJSONPath
+    }
+
+    // Prevent es6 bundled lib crash.
+    if (fs.existsSync(tsConfigPath)) {
+        const tsConfig = require(tsConfigPath);
+        const srcDirectory = path.resolve(mainDirectory, tsConfig.compilerOptions.rootDir);
+
+        const shaderGlob = srcDirectory + "/**/*.fx";
+        const shaderTSGlob = srcDirectory + "/**/*.fx.ts";
+
+        for (let library of settings.libraries) {
+            const entryPath = path.join(srcDirectory, library.entry);
+
+            library.computed = {
+                entryPath
+            };
+        }
+
+        settings.computed.srcDirectory = srcDirectory;
+        settings.computed.shaderGlob = shaderGlob;
+        settings.computed.shaderTSGlob = shaderTSGlob;
     }
 });
 

+ 14 - 1
Tools/Config/config.json

@@ -499,9 +499,22 @@
                         "babylonjs": "BABYLON",
                         "babylonjs-loaders": "BABYLON",
                         "babylonjs-serializers": "BABYLON",
-                        "babylonjs-gui": "BABYLON.GUI"
+                        "babylonjs-gui": "BABYLON.GUI",
+                        "@babylonjs/core": "BABYLON",
+                        "@babylonjs/loaders": "BABYLON",
+                        "@babylonjs/serializers": "BABYLON",
+                        "@babylonjs/gui": "BABYLON.GUI"
                     }
                 }
+            },
+            "es6": {
+                "webpackBuild": {
+                    "dependencies": [
+                        "node_modules/re-resizable/lib/index.es5.js",
+                        "Tools/**/*"
+                    ]
+                },
+                "packageName": "@babylonjs/inspector"
             }
         }
     },

+ 91 - 34
Tools/Gulp/tasks/gulpTasks-librariesES6.js

@@ -40,7 +40,7 @@ var dep = function(settings) {
 
     const tsconfig = require(settings.computed.tsConfigPath);
     for (let pathName in tsconfig.compilerOptions.paths) {
-        var paths = tsconfig.compilerOptions.paths[pathName];
+        let paths = tsconfig.compilerOptions.paths[pathName];
         for (let dep of paths) {
             const fullPath = path.resolve(settings.computed.mainDirectory, 
                 tsconfig.compilerOptions.baseUrl, 
@@ -49,36 +49,15 @@ var dep = function(settings) {
         }
     }
 
-    return gulp.src(copyPaths, { base: config.computed.rootFolder })
-        .pipe(gulp.dest(config.computed.sourceES6Folder));
-}
-
-/**
- * TSC Build.
- */
-var build = function(settings, cb) {
-    // Launch TSC.
-    const options = {
-        cwd: settings.computed.sourceES6Directory,
-        verbose: true
-    };
-
-    let command = `tsc --inlineSources --sourceMap true -t es5 -m esNext --outDir "${settings.computed.distES6Directory}"`;
-    shelljs.exec(command, options, function(code, stdout, stderr) {
-        if (stderr) {
-            console.log(stderr);
-        }
-        if (stdout) {
-            console.log(stdout);
+    if (settings.build.es6.webpackBuild && settings.build.es6.webpackBuild.dependencies) {
+        for (let pathName of settings.build.es6.webpackBuild.dependencies) {
+            const dependencyPath = path.join(config.computed.rootFolder, pathName);
+            copyPaths.push(dependencyPath);
         }
+    }
 
-        if (code !== 0) {
-            cb("TSC Failed.")
-        }
-        else {
-            cb();
-        }
-    });
+    return gulp.src(copyPaths, { base: config.computed.rootFolder })
+        .pipe(gulp.dest(config.computed.sourceES6Folder));
 }
 
 /**
@@ -168,9 +147,76 @@ var appendLoseDTSFiles = function(settings) {
 }
 
 /**
+ * TSC Build.
+ */
+var build = function(settings, cb) {
+    // Launch TSC.
+    const options = {
+        cwd: settings.computed.sourceES6Directory,
+        verbose: true
+    };
+
+    let command = `tsc --inlineSources --sourceMap true -t es5 -m esNext --outDir "${settings.computed.distES6Directory}"`;
+    shelljs.exec(command, options, function(code, stdout, stderr) {
+        if (stderr) {
+            console.log(stderr);
+        }
+        if (stdout) {
+            console.log(stdout);
+        }
+
+        if (code !== 0) {
+            cb("TSC Failed.")
+        }
+        else {
+            cb();
+        }
+    });
+}
+
+/**
+ * Webpack Build.
+ */
+var buildWebpack = function(module, cb) {
+    const gulpPath = path.join(config.computed.sourceES6Folder, "Tools/Gulp");
+    // Launch TSC.
+    const options = {
+        cwd: gulpPath,
+        verbose: true
+    };
+
+    let command = `gulp ${module}`;
+    shelljs.exec(command, options, function(code, stdout, stderr) {
+        if (stderr) {
+            console.log(stderr);
+        }
+        if (stdout) {
+            console.log(stdout);
+        }
+
+        if (code !== 0) {
+            cb("Webpack Build Failed.")
+        }
+        else {
+            cb();
+        }
+    });
+}
+
+/**
+ * Copy Webpack Dist.
+ */
+var copyWebpackDist = function(settings, module) {
+    var es6Config = require(path.join(config.computed.sourceES6Folder, "Tools/Config/config"));
+
+    return gulp.src(es6Config[module].computed.distDirectory + "/**/*")
+        .pipe(gulp.dest(settings.computed.distES6Directory));
+}
+
+/**
  * Dynamic es 6 module creation.
  */
-function buildES6Library(settings) {
+function buildES6Library(settings, module) {
     // Creates the required tasks.
     var tasks = [];
 
@@ -179,10 +225,21 @@ function buildES6Library(settings) {
     var dependencies = function() { return dep(settings); };
     var adaptSourceImportPaths = function() { return modifySources(settings); };
     var adaptTsConfigImportPaths = function(cb) { return modifyTsConfig(settings, cb); };
-    var buildes6 = function(cb) { return build(settings, cb) };
-    var appendLoseDTS = function() { return appendLoseDTSFiles(settings) };
+    var buildSteps = null;
+    if (settings.build.es6.webpackBuild) {
+        buildSteps = [
+            function buildes6(cb) { return buildWebpack(module, cb) },
+            function copyDist() { return copyWebpackDist(settings, module) }
+        ];
+    }
+    else {
+        buildSteps = [
+            function buildes6(cb) { return build(settings, cb) }, 
+            function appendLoseDTS() { return appendLoseDTSFiles(settings) }
+        ];
+    }
 
-    tasks.push(cleanup, copySource, dependencies, adaptSourceImportPaths, adaptTsConfigImportPaths, buildes6, appendLoseDTS);
+    tasks.push(cleanup, copySource, dependencies, adaptSourceImportPaths, adaptTsConfigImportPaths, ...buildSteps);
 
     return gulp.series.apply(this, tasks);
 }
@@ -192,5 +249,5 @@ function buildES6Library(settings) {
  */
 config.modules.map(function(module) {
     const settings = config[module];
-    gulp.task(module + "-es6", buildES6Library(settings));
+    gulp.task(module + "-es6", buildES6Library(settings, module));
 });

+ 32 - 0
Tools/WebpackPlugins/babylonExternals.js

@@ -35,6 +35,38 @@ module.exports = function nodeExternals(options) {
                 amd: "babylonjs"
             });
         }
+        else if (/^@babylonjs\/serializers.*$/i.test(request)) {
+            callback(null, {
+                root: "BABYLON",
+                commonjs: "@babylonjs/serializers",
+                commonjs2: "@babylonjs/serializers",
+                amd: "@babylonjs/serializers"
+            });
+        }
+        else if (/^@babylonjs\/loaders.*$/i.test(request)) {
+            callback(null, {
+                root: "BABYLON",
+                commonjs: "@babylonjs/loaders",
+                commonjs2: "@babylonjs/loaders",
+                amd: "@babylonjs/loaders"
+            });
+        }
+        else if (/^@babylonjs\/gui.*$/i.test(request)) {
+            callback(null, {
+                root: ["BABYLON", "GUI"],
+                commonjs: "@babylonjs/gui",
+                commonjs2: "@babylonjs/gui",
+                amd: "@babylonjs/gui"
+            });
+        }
+        else if (/^@babylonjs\/core.*$/i.test(request)) {
+            callback(null, {
+                root: "BABYLON",
+                commonjs: "@babylonjs/core",
+                commonjs2: "@babylonjs/core",
+                amd: "@babylonjs/core"
+            });
+        }
         else {
             callback();
         }