瀏覽代碼

Merge pull request #7950 from RaananW/fix-viewer-webpack-stream

Latst webpack & webpack stream are now in use
David Catuhe 5 年之前
父節點
當前提交
7da1d217e8
共有 3 個文件被更改,包括 85 次插入68 次删除
  1. 78 65
      Tools/Gulp/tasks/gulpTasks-viewerLibraries.js
  2. 4 0
      dist/preview release/what's new.md
  3. 3 3
      package.json

+ 78 - 65
Tools/Gulp/tasks/gulpTasks-viewerLibraries.js

@@ -13,93 +13,106 @@ var addModuleExports = require("../helpers/gulp-addModuleExports");
 // Import Build Config
 var config = require("../../Config/config.json");
 
+const webpack = require("webpack");
+
 /**
  * Build the viewer
  */
-var buildViewerLibrary = function(library, settings) {
+var buildViewerLibrary = function (library, settings, out) {
     const sequence = [];
     var outputDirectory = config.build.outputDirectory + settings.build.distOutputDirectory;
 
-    settings.build.outputs.forEach(out => {
-        let wpConfig = require(settings.build.webpack);
-        if (!out.minified) {
-            wpConfig.mode = "development";
-        }
+    let wpConfig = require(settings.build.webpack);
+    if (!out.minified) {
+        wpConfig.mode = "development";
+    }
 
-        let wpBuild = webpackStream(wpConfig, require("webpack"));
+    let wpBuild = webpackStream(wpConfig, webpack);
 
-        //shoud dtsBundle create the declaration?
-        if (settings.build.dtsBundle) {
-            let event = wpBuild
-                .pipe(through.obj(function(file, enc, cb) {
-                    // only declaration files
-                    const isdts = /\.d\.ts$/.test(file.path);
-                    if (isdts) this.push(file);
-                    cb();
-                }))
-                .pipe(gulp.dest(outputDirectory));
-            // dts-bundle does NOT support (gulp) streams, so files have to be saved and reloaded, 
-            // until I fix it
-            event.on("end", function() {
-                // create the file
-                dtsBundle.bundle(settings.build.dtsBundle);
-                // process the declaration
-                let fileLocation = path.join(path.dirname(settings.build.dtsBundle.main), settings.build.dtsBundle.out);
-                processDeclaration(fileLocation, settings.build.umd.packageName, settings.build.umd.processDeclaration);
-            });
-        }
-
-        let build = wpBuild
-            .pipe(through.obj(function(file, enc, cb) {
-                // only pipe js files
-                const isJs = /\.js$/.test(file.path);
-                if (isJs) this.push(file);
+    //shoud dtsBundle create the declaration?
+    if (settings.build.dtsBundle) {
+        let event = wpBuild
+            .pipe(through.obj(function (file, enc, cb) {
+                // only declaration files
+                const isdts = /\.d\.ts$/.test(file.path);
+                if (isdts) this.push(file);
                 cb();
             }))
-            .pipe(addModuleExports(library.moduleDeclaration, { subModule: false, extendsRoot: false, externalUsingBabylon: true, noBabylonInit: true }));
-
-        function processDestination(dest) {
-            var outputDirectory = config.build.outputDirectory + dest.outputDirectory;
-            build = build
-                .pipe(rename(dest.filename))
-                .pipe(gulp.dest(outputDirectory));
-
-            if (dest.addBabylonDeclaration) {
-                // include the babylon declaration
-                if (dest.addBabylonDeclaration === true) {
-                    dest.addBabylonDeclaration = ["babylon.module.d.ts"];
-                }
-                var decsToAdd = dest.addBabylonDeclaration.map(function(dec) {
-                    return config.build.outputDirectory + '/' + dec;
-                });
-                sequence.unshift(gulp.src(decsToAdd)
-                    .pipe(rename(function(path) {
-                        path.dirname = '';
-                    }))
-                    .pipe(gulp.dest(outputDirectory)))
+            .pipe(gulp.dest(outputDirectory));
+        // dts-bundle does NOT support (gulp) streams, so files have to be saved and reloaded, 
+        // until I fix it
+        event.on("end", function () {
+            // create the file
+            dtsBundle.bundle(settings.build.dtsBundle);
+            // process the declaration
+            let fileLocation = path.join(path.dirname(settings.build.dtsBundle.main), settings.build.dtsBundle.out);
+            processDeclaration(fileLocation, settings.build.umd.packageName, settings.build.umd.processDeclaration);
+        });
+    }
+
+    let build = wpBuild
+        .pipe(through.obj(function (file, enc, cb) {
+            // only pipe js files
+            const isJs = /\.js$/.test(file.path);
+            if (isJs) this.push(file);
+            cb();
+        }))
+        .pipe(addModuleExports(library.moduleDeclaration, {
+            subModule: false,
+            extendsRoot: false,
+            externalUsingBabylon: true,
+            noBabylonInit: true
+        }));
+
+    function processDestination(dest) {
+        var outputDirectory = config.build.outputDirectory + dest.outputDirectory;
+        build = build
+            .pipe(rename(dest.filename))
+            .pipe(gulp.dest(outputDirectory));
+
+        if (dest.addBabylonDeclaration) {
+            // include the babylon declaration
+            if (dest.addBabylonDeclaration === true) {
+                dest.addBabylonDeclaration = ["babylon.module.d.ts"];
             }
+            var decsToAdd = dest.addBabylonDeclaration.map(function (dec) {
+                return config.build.outputDirectory + '/' + dec;
+            });
+            sequence.unshift(gulp.src(decsToAdd)
+                .pipe(rename(function (path) {
+                    path.dirname = '';
+                }))
+                .pipe(gulp.dest(outputDirectory)))
         }
+    }
 
-        out.destinations.forEach(dest => {
-            processDestination(dest);
-        });
+    out.destinations.forEach(dest => {
+        processDestination(dest);
+    });
 
-        sequence.push(build);
+    sequence.push(build);
 
-    });
+    // });
 
     return merge2(sequence);
 }
 
+function buildViewerOutputs(settings, library) {
+    var outputBuilds = settings.build.outputs.map(out => {
+        var buildOutput = function () {
+            return buildViewerLibrary(library, settings, out);
+        }
+        return buildOutput;
+    });
+    return (outputBuilds);
+}
+
 /**
  * Dynamic viewer module creation In Serie for WebPack leaks.
  */
 function buildViewerLibraries(settings) {
-    var tasks = settings.libraries.map(function(library) {
-        var build = function(cb) {
-            return buildViewerLibrary(library, settings);
-        }
-        return build;
+    var tasks = settings.libraries.map(function (library) {
+        return buildViewerOutputs(settings, library);
     });
 
     return gulp.series.apply(this, tasks);
@@ -109,7 +122,7 @@ function buildViewerLibraries(settings) {
 /**
  * Dynamic viewer module creation.
  */
-config.viewerModules.map(function(module) {
+config.viewerModules.map(function (module) {
     var settings = config[module];
 
     // Build the libraries.

+ 4 - 0
dist/preview release/what's new.md

@@ -76,6 +76,10 @@
 
 - Added support for Additive Animation Blending. Existing animations can be converted to additive using the new MakeAnimationAdditive method for Skeletons, AnimationGroups and Animations. Animations can be played additively using the new isAdditive input parameter to the begin animation methods. ([c-morten](https://github.com/c-morten))
 
+### Build
+
+- Fixed an issue with gulp webpack, webpack stream and the viewer ([RaananW](https://github.com/RaananW))
+
 ## Bugs
 
 - Fix infinite loop in `GlowLayer.unReferenceMeshFromUsingItsOwnMaterial` ([Popov72](https://github.com/Popov72)

+ 3 - 3
package.json

@@ -99,14 +99,14 @@
         "tslint": "^5.11.0",
         "typedoc": "^0.15.4",
         "typescript": "~3.8.3",
-        "webpack": "4.41.0",
+        "webpack": "~4.42.0",
         "webpack-bundle-analyzer": "^3.1.0",
         "webpack-cli": "^3.3.9",
         "webpack-dev-server": "^3.1.14",
-        "webpack-stream": "5.0.0",
+        "webpack-stream": "~5.2.0",
         "xhr2": "^0.1.4",
         "xmlbuilder": "8.2.2",
         "react-color": "^2.18.0",
         "@types/react-color": "^3.0.1"
     }
-}
+}