浏览代码

Add Build Artifacts Caching

sebastien 6 年之前
父节点
当前提交
2653faa8be

+ 1 - 3
Tools/Gulp/config.json

@@ -226,9 +226,7 @@
                 "moduleName": "BABYLON",
                 "importsToRemove": [],
                 "classMap": {
-                    "babylonjs": "BABYLON",
-                    "babylonjs-loaders": "BABYLON",
-                    "babylonjs-serializers": "BABYLON"
+                    "babylonjs": "BABYLON"
                 }
             }
         }

+ 23 - 9
Tools/Gulp/helpers/gulp-processAmdDeclarationToModule.js

@@ -25,15 +25,29 @@ var processData = function(data, options) {
             line = `${spaces}import { ${type} } from "${module}";`;
         }
 
-        // Append Module Name
-        // Declaration
-        line = line.replace(/declare module "/g, `declare module "${moduleName}/`);
-        // From
-        line = line.replace(/ from "/g, ` from "${moduleName}/`);
-        // Module augmentation
-        line = line.replace(/    module "/g, `    module "${moduleName}/`);
-        // Inlined Import
-        line = line.replace(/import\("/g, `import("${moduleName}/`);
+        // Checks if line is about external module
+        var externalModule = false;
+        if (options.externals) {
+            for (let ext in options.externals) {
+                externalModule = line.indexOf(ext) > -1;
+                if (externalModule) {
+                    break;
+                }
+            }
+        }
+        // If not Append Module Name
+        if (!externalModule) {
+            // Declaration
+            line = line.replace(/declare module "/g, `declare module "${moduleName}/`);
+            // From
+            line = line.replace(/ from "/g, ` from "${moduleName}/`);
+            // Module augmentation
+            line = line.replace(/    module "/g, `    module "${moduleName}/`);
+            // Inlined Import
+            line = line.replace(/import\("/g, `import("${moduleName}/`);
+            // Side Effect Import
+            line = line.replace(/import "/g, `import "${moduleName}/`);
+        }
 
         lines[index] = line;
     }

+ 60 - 53
Tools/Gulp/tasks/gulpTasks-libraries.js

@@ -3,7 +3,6 @@ var gulp = require("gulp");
 var webpack = require('webpack');
 var webpackStream = require("webpack-stream");
 var cp = require('child_process');
-var merge2 = require("merge2");
 var path = require("path");
 
 // Gulp Helpers
@@ -28,70 +27,76 @@ var buildShaders = function(settings) {
 /**
  * Build a single library (one of the material of mat lib) from a module (materialsLibrary for instance)
  */
-var buildExternalLibrariesMultiEntry = function(libraries, settings, cb) {
+var buildExternalLibrariesMultiEntry = function(libraries, settings, isMin) {
     // Convert Module to Namespace for globals
-    const sequence = [];
     var outputDirectory = config.build.outputDirectory + settings.build.distOutputDirectory;
 
+    // Does name contain .min. for min files.
     var isMinOutputName = libraries[0].output.indexOf(".min.") > -1;
 
     // Webpack Config.
     var wpConfig = require(settings.build.webpack);
+    // Create multi entry list.
     wpConfig.entry = { };
-    wpConfig.output.filename = isMinOutputName ? '[name].js' : '[name].min.js';
     for (let library of settings.libraries) {
-        let name = library.output.replace(isMinOutputName ? ".js" : ".min.js", "");
+        let name = library.output.replace(isMinOutputName ? ".min.js" : ".js", "");
         wpConfig.entry[name] = path.resolve(wpConfig.context, library.entry);
     }
 
+    // Create output by type (min vs max).
+    if (isMin) {
+        wpConfig.output.filename = isMinOutputName ? '[name].min.js' : '[name].js';
+    }
+    else {
+        // Generate unminified file.
+        wpConfig.mode = "development";
+        wpConfig.output.filename = isMinOutputName ? '[name].js' : '[name].max.js';
+    }
+
     // Generate minified file.
-    let wpBuildMin = webpackStream(wpConfig, webpack);
-    let buildEventMin = wpBuildMin.pipe(gulp.dest(outputDirectory));
-    sequence.push(buildEventMin);
-
-    // Generate unminified file.
-    wpConfig.mode = "development";
-    // Allow babylon.max.js and babylon.js
-    wpConfig.output.filename = isMinOutputName ? '[name].max.js' : '[name].js';
-    //wpConfig.output.filename = library.maxOutput || wpConfig.output.filename.replace(".min", "");
-    let wpBuildMax = webpackStream(wpConfig, webpack);
-    let buildEventMax = wpBuildMax.pipe(gulp.dest(outputDirectory));
-    sequence.push(buildEventMax);
-
-    return merge2(sequence)
-        .on("end", function() {
-            // TODO. Generate all d.ts
-            let library = libraries[0];
-            if (!library.preventLoadLibrary) {
-                let fileLocation = path.join(outputDirectory, settings.build.processDeclaration.filename);
-                // Generate DTS the Dts Bundle way...
-                // dtsBundle.bundle(settings.build.dtsBundle);
-
-                let srcDirectory = settings.build.srcDirectory;
-                let depthCount = srcDirectory.match(/\//g).length - srcDirectory.match(/\.\.\//g).length;
-                let tempDirectory = "";
-                for (let i = 0; i < depthCount; i++) {
-                    tempDirectory += "../"
-                }
-                tempDirectory += ".temp/";
-
-                // Generate DTS the old way...
-                cp.execSync('tsc --module amd --outFile "' + tempDirectory + 'amd.js" --emitDeclarationOnly true', {
-                    cwd: settings.build.srcDirectory
-                });
-
-                // Convert the tsc AMD BUNDLED declaration to our expected one
-                processAmdDeclarationToModule("../../.temp/amd.d.ts", {
-                    output: fileLocation,
-                    moduleName: settings.build.processDeclaration.packageName,
-                    entryPoint: library.entry
-                });
-
-                // Convert Module to Namespace for globals
-                processModuleDeclarationToNamespace(fileLocation, settings.build.processDeclaration);
-            }
-            cb();
+    let wpBuild = webpackStream(wpConfig, webpack);
+    return wpBuild.pipe(gulp.dest(outputDirectory));
+}
+
+/**
+ * Build DTS Files
+ */
+var buildDTSFiles = function(libraries, settings, cb) {
+    // Convert Module to Namespace for globals
+    var outputDirectory = config.build.outputDirectory + settings.build.distOutputDirectory;
+
+    // TODO. Generate all d.ts
+    let library = libraries[0];
+    if (!library.preventLoadLibrary) {
+        // Find declaration path.
+        let fileLocation = path.join(outputDirectory, settings.build.processDeclaration.filename);
+
+        // Create temp directory.
+        let srcDirectory = settings.build.srcDirectory;
+        let depthCount = srcDirectory.match(/\//g).length - srcDirectory.match(/\.\.\//g).length;
+        let tempDirectory = "";
+        for (let i = 0; i < depthCount; i++) {
+            tempDirectory += "../"
+        }
+        tempDirectory += ".temp/";
+
+        // Generate DTS the old way...
+        cp.execSync('tsc --module amd --outFile "' + tempDirectory + 'amd.js" --emitDeclarationOnly true', {
+            cwd: settings.build.srcDirectory
         });
+
+        // Convert the tsc AMD BUNDLED declaration to our expected one
+        processAmdDeclarationToModule("../../.temp/amd.d.ts", {
+            output: fileLocation,
+            moduleName: settings.build.processDeclaration.packageName,
+            entryPoint: library.entry,
+            externals: settings.build.processDeclaration.classMap,
+        });
+
+        // Convert Module to Namespace for globals
+        processModuleDeclarationToNamespace(fileLocation, settings.build.processDeclaration);
+    }
+    cb();
 }
 
 /**
@@ -104,9 +109,11 @@ function buildExternalLibraries(settings) {
     // Creates the required tasks.
     var tasks = [];
     var shaders = function() { return buildShaders(settings); };
-    var build = function(cb) { return buildExternalLibrariesMultiEntry(settings.libraries, settings, cb) };
+    var buildMin = function() { return buildExternalLibrariesMultiEntry(settings.libraries, settings, true) };
+    var buildMax = function() { return buildExternalLibrariesMultiEntry(settings.libraries, settings, false) };
+    var buildDTS = function(cb) { return buildDTSFiles(settings.libraries, settings, cb) };
 
-    tasks.push(shaders, build);
+    tasks.push(shaders, buildMin, buildMax, buildDTS);
 
     return gulp.series.apply(this, tasks);
 }

+ 3 - 1
gui/webpack.config.js

@@ -1,6 +1,7 @@
 const path = require('path');
 const webpack = require('webpack');
 const CleanWebpackPlugin = require('clean-webpack-plugin');
+const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
 
 module.exports = {
     context: __dirname,
@@ -39,7 +40,7 @@ module.exports = {
             loader: 'awesome-typescript-loader',
             options: {
                 configFileName: '../../gui/tsconfig.json',
-                declarationDir: '../../dist/preview release/gui/build'
+                declaration: false
             }
         }]
     },
@@ -51,6 +52,7 @@ module.exports = {
         port: 9000
     },
     plugins: [
+        new HardSourceWebpackPlugin(),
         new CleanWebpackPlugin([
             path.resolve(__dirname, './src/**/*.js'),
             path.resolve(__dirname, './src/**/*.map')

+ 3 - 1
inspector/webpack.config.js

@@ -2,6 +2,7 @@ const path = require('path');
 const webpack = require('webpack');
 const MiniCssExtractPlugin = require("mini-css-extract-plugin");
 const CleanWebpackPlugin = require('clean-webpack-plugin');
+const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
 
 module.exports = {
     context: __dirname,
@@ -58,7 +59,7 @@ module.exports = {
             loader: 'awesome-typescript-loader',
             options: {
                 configFileName: '../../inspector/tsconfig.json',
-                declarationDir: '../../dist/preview release/inspector/build'
+                declaration: false
             }
         },
         {
@@ -85,6 +86,7 @@ module.exports = {
         hints: false
     },
     plugins: [
+        new HardSourceWebpackPlugin(),
         new CleanWebpackPlugin([
             path.resolve(__dirname, './src/**/*.js'),
             path.resolve(__dirname, './src/**/*.map')

+ 3 - 1
loaders/webpack.config.js

@@ -1,6 +1,7 @@
 const path = require('path');
 const webpack = require('webpack');
 const CleanWebpackPlugin = require('clean-webpack-plugin');
+const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
 
 module.exports = {
     context: __dirname,
@@ -42,7 +43,7 @@ module.exports = {
                 loader: 'awesome-typescript-loader',
                 options: {
                     configFileName: '../../loaders/tsconfig.json',
-                    declarationDir: '../../dist/preview release/loaders/build'
+                    declaration: false
                 }
             }]
         }]
@@ -55,6 +56,7 @@ module.exports = {
         port: 9000
     },
     plugins: [
+        new HardSourceWebpackPlugin(),
         new CleanWebpackPlugin([
             path.resolve(__dirname, './src/**/*.js'),
             path.resolve(__dirname, './src/**/*.map')

+ 3 - 1
materialsLibrary/webpack.config.js

@@ -1,6 +1,7 @@
 const path = require('path');
 const webpack = require('webpack');
 const CleanWebpackPlugin = require('clean-webpack-plugin');
+const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
 
 module.exports = {
     context: __dirname,
@@ -42,7 +43,7 @@ module.exports = {
                 loader: 'awesome-typescript-loader',
                 options: {
                     configFileName: '../../materialsLibrary/tsconfig.json',
-                    declarationDir: '../../dist/preview release/materialsLibrary/build'
+                    declaration: false
                 }
             }]
         }]
@@ -55,6 +56,7 @@ module.exports = {
         port: 9000
     },
     plugins: [
+        new HardSourceWebpackPlugin(),
         new CleanWebpackPlugin([
             path.resolve(__dirname, './src/**/*.js'),
             path.resolve(__dirname, './src/**/*.map')

+ 1 - 0
package.json

@@ -70,6 +70,7 @@
         "gulp-typedoc": "^2.2.0",
         "gulp-typescript": "4.0.2",
         "gulp-webserver": "^0.9.1",
+        "hard-source-webpack-plugin": "^0.12.0",
         "karma": "^2.0.5",
         "karma-browserstack-launcher": "^1.3.0",
         "karma-chai": "^0.1.0",

+ 2 - 2
postProcessLibrary/legacy/legacy-asciiArt.ts

@@ -1,4 +1,4 @@
-import * as postProcessLibrary from "../src/asciiArt/index";
+import * as postProcessLibrary from "../asciiArt/index";
 
 /**
  * This is the entry point for the UMD module.
@@ -11,4 +11,4 @@ if (typeof globalObject !== "undefined") {
     }
 }
 
-export * from "../src/asciiArt/index";
+export * from "../asciiArt/index";

+ 2 - 2
postProcessLibrary/legacy/legacy-digitalRain.ts

@@ -1,4 +1,4 @@
-import * as postProcessLibrary from "../src/digitalRain/index"
+import * as postProcessLibrary from "../digitalRain/index";
 
 /**
  * This is the entry point for the UMD module.
@@ -11,4 +11,4 @@ if (typeof globalObject !== "undefined") {
     }
 }
 
-export * from "../src/digitalRain/index";
+export * from "../digitalRain/index";

+ 2 - 2
postProcessLibrary/legacy/legacy.ts

@@ -1,4 +1,4 @@
-import * as postProcessLibrary from "../src/index";
+import * as postProcessLibrary from "../index";
 
 /**
  *
@@ -12,4 +12,4 @@ if (typeof globalObject !== "undefined") {
     }
 }
 
-export * from "../src/index";
+export * from "../index";

+ 1 - 1
postProcessLibrary/tsconfig.json

@@ -21,7 +21,7 @@
         "skipDefaultLibCheck": true,
         "skipLibCheck": true,
         "baseUrl": "./src/",
-        "rootDir": "./",
+        "rootDir": "./src/",
         "paths": {
             "babylonjs": [
                 "../../dist/preview release/babylon.module.d.ts"

+ 4 - 2
postProcessLibrary/webpack.config.js

@@ -1,9 +1,10 @@
 const path = require('path');
 const webpack = require('webpack');
 const CleanWebpackPlugin = require('clean-webpack-plugin');
+const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
 
 module.exports = {
-    context: __dirname,
+    context: path.resolve(__dirname, './src'),
     entry: {
         'babylonjs-postProcessesLibrary': path.resolve(__dirname, './legacy/legacy.ts'),
     },
@@ -39,7 +40,7 @@ module.exports = {
             loader: 'awesome-typescript-loader',
             options: {
                 configFileName: '../../postProcessLibrary/tsconfig.json',
-                declarationDir: '../../dist/preview release/postProcessesLibrary/build'
+                declaration: false
             }
         }]
     },
@@ -51,6 +52,7 @@ module.exports = {
         port: 9000
     },
     plugins: [
+        new HardSourceWebpackPlugin(),
         new CleanWebpackPlugin([
             path.resolve(__dirname, './src/**/*.js'),
             path.resolve(__dirname, './src/**/*.map')

+ 3 - 1
proceduralTexturesLibrary/webpack.config.js

@@ -1,6 +1,7 @@
 const path = require('path');
 const webpack = require('webpack');
 const CleanWebpackPlugin = require('clean-webpack-plugin');
+const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
 
 module.exports = {
     context: __dirname,
@@ -40,7 +41,7 @@ module.exports = {
             loader: 'awesome-typescript-loader',
             options: {
                 configFileName: '../../proceduralTexturesLibrary/tsconfig.json',
-                declarationDir: '../../dist/preview release/proceduralTexturesLibrary/build'
+                declaration: false
             }
         }]
     },
@@ -52,6 +53,7 @@ module.exports = {
         port: 9000
     },
     plugins: [
+        new HardSourceWebpackPlugin(),
         new CleanWebpackPlugin([
             path.resolve(__dirname, './src/**/*.js'),
             path.resolve(__dirname, './src/**/*.map')

+ 3 - 1
serializers/webpack.config.js

@@ -1,6 +1,7 @@
 const path = require('path');
 const webpack = require('webpack');
 const CleanWebpackPlugin = require('clean-webpack-plugin');
+const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
 
 module.exports = {
     context: __dirname,
@@ -42,7 +43,7 @@ module.exports = {
                 loader: 'awesome-typescript-loader',
                 options: {
                     configFileName: '../../serializers/tsconfig.json',
-                    declarationDir: '../../dist/preview release/serializers/build'
+                    declaration: false
                 }
             }]
         }]
@@ -55,6 +56,7 @@ module.exports = {
         port: 9000
     },
     plugins: [
+        new HardSourceWebpackPlugin(),
         new CleanWebpackPlugin([
             path.resolve(__dirname, './src/**/*.js'),
             path.resolve(__dirname, './src/**/*.map')

+ 3 - 1
src/webpack.config.js

@@ -1,6 +1,7 @@
 const path = require('path');
 const webpack = require('webpack');
 const CleanWebpackPlugin = require('clean-webpack-plugin');
+const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
 
 module.exports = {
     context: __dirname,
@@ -39,7 +40,7 @@ module.exports = {
             loader: 'awesome-typescript-loader',
             options: {
                 configFileName: '../../src/tsconfig.json',
-                declarationDir: '../../dist/preview release/build'
+                declaration: false
             }
         }]
     },
@@ -51,6 +52,7 @@ module.exports = {
         port: 9000
     },
     plugins: [
+        new HardSourceWebpackPlugin(),
         new webpack.WatchIgnorePlugin([
             /\.js$/,
             /\.d\.ts$/,