sebavan 7 лет назад
Родитель
Сommit
269e1cecb2

+ 8 - 8
Tools/Gulp/config.json

@@ -51,7 +51,7 @@
             }
         ],
         "build": {
-            "webpack": "../../../src/webpack.config.js",
+            "webpack": "../../src/webpack.config.js",
             "srcDirectory": "../../src/",
             "loseDTSFiles": "../../src/LibDeclarations/*.d.ts",
             "distOutputDirectory": "/",
@@ -173,7 +173,7 @@
             }
         ],
         "build": {
-            "webpack": "../../../materialsLibrary/webpack.config.js",
+            "webpack": "../../materialsLibrary/webpack.config.js",
             "srcDirectory": "../../materialsLibrary/src/",
             "distOutputDirectory": "/materialsLibrary/",
             "processDeclaration": {
@@ -212,7 +212,7 @@
             }
         ],
         "build": {
-            "webpack": "../../../postProcessLibrary/webpack.config.js",
+            "webpack": "../../postProcessLibrary/webpack.config.js",
             "srcDirectory": "../../postProcessLibrary/src/",
             "distOutputDirectory": "/postProcessesLibrary/",
             "processDeclaration": {
@@ -291,7 +291,7 @@
             }
         ],
         "build": {
-            "webpack": "../../../proceduralTexturesLibrary/webpack.config.js",
+            "webpack": "../../proceduralTexturesLibrary/webpack.config.js",
             "srcDirectory": "../../proceduralTexturesLibrary/src/",
             "distOutputDirectory": "/proceduralTexturesLibrary/",
             "processDeclaration": {
@@ -345,7 +345,7 @@
             }
         ],
         "build": {
-            "webpack": "../../../loaders/webpack.config.js",
+            "webpack": "../../loaders/webpack.config.js",
             "srcDirectory": "../../loaders/src/",
             "distOutputDirectory": "/loaders/",
             "processDeclaration": {
@@ -403,7 +403,7 @@
             }
         ],
         "build": {
-            "webpack": "../../../serializers/webpack.config.js",
+            "webpack": "../../serializers/webpack.config.js",
             "srcDirectory": "../../serializers/src/",
             "distOutputDirectory": "/serializers/",
             "processDeclaration": {
@@ -453,7 +453,7 @@
             }
         ],
         "build": {
-            "webpack": "../../../gui/webpack.config.js",
+            "webpack": "../../gui/webpack.config.js",
             "srcDirectory": "../../gui/src/",
             "distOutputDirectory": "/gui/",
             "processDeclaration": {
@@ -486,7 +486,7 @@
         ],
         "build": {
             "ignoreInTestMode": true,
-            "webpack": "../../../inspector/webpack.config.js",
+            "webpack": "../../inspector/webpack.config.js",
             "srcDirectory": "../../inspector/src/",
             "distOutputDirectory": "/inspector/",
             "processDeclaration": {

+ 4 - 2
Tools/Gulp/tasks/gulpTasks-libraries.js

@@ -14,7 +14,8 @@ var processModuleDeclarationToNamespace = require('../helpers/gulp-processModule
 var del = require("del");
 
 // Import Build Config
-var config = require("../config.json");
+var configPath = "../config.json";
+var config = require(configPath);
 
 // Constants
 const tempTypingsFile = "tempTypings.js";
@@ -48,7 +49,8 @@ var buildExternalLibrariesMultiEntry = function(libraries, settings, isMin) {
     var isMinOutputName = libraries[0].output.indexOf(".min.") > -1;
 
     // Webpack Config.
-    var wpConfig = require(settings.build.webpack);
+    var configFolder = path.dirname(path.resolve(__dirname, configPath));
+    var wpConfig = require(path.resolve(configFolder, settings.build.webpack));
 
     // Create multi entry list.
     wpConfig.entry = { };

+ 5 - 2
Tools/Gulp/tasks/gulpTasks-watchLibraries.js

@@ -7,7 +7,8 @@ var processShaders = require("../helpers/gulp-processShaders");
 var uncommentShaders = require('../helpers/gulp-removeShaderComments');
 
 // Read the full config.
-var config = require("../config.json");
+var configPath = "../config.json";
+var config = require(configPath);
 
 /**
  * Watch ts files and fire repective tasks.
@@ -24,7 +25,9 @@ gulp.task("watchLibraries", function startWatch() {
                     continue;
                 }
 
-                let wpConfig = require(settings.webpack);
+                var configFolder = path.dirname(path.resolve(__dirname, configPath));
+                var wpConfig = require(path.resolve(configFolder, settings.build.webpack));
+
                 // watch on.
                 wpConfig.watch = true;
                 // dev mode and absolute path sourcemaps for debugging

+ 67 - 0
Tools/WebpackPlugins/babylonWebpackConfig.js

@@ -0,0 +1,67 @@
+const path = require('path');
+const webpack = require('webpack');
+const babylonExternals = require('./babylonExternals');
+const hardSourceWebpackPlugin = require('hard-source-webpack-plugin');
+
+var configPath = "../Gulp/config.json";
+const configFolder = path.dirname(path.resolve(__dirname, configPath));
+const config = require(configPath);
+
+module.exports = function defaultConfig(options) {
+    if (!options) {
+        throw "Options are mandatory to create the config.";
+    }
+
+    const module = options.module;
+    const settings = config[module];
+
+    const src = path.resolve(__dirname, settings.build.srcDirectory);
+    const webpackFolder = path.dirname(path.resolve(configFolder, settings.build.webpack));
+
+    options.resolveExtensions = options.resolveExtensions || [];
+
+    return {
+        context: src,
+        entry: {
+            [settings.build.processDeclaration.packageName]: path.resolve(src, settings.libraries[0].entry),
+        },
+        output: {
+            path: path.resolve(__dirname, config.build.outputDirectory) + settings.build.distOutputDirectory,
+            filename: settings.libraries[0].output,
+            libraryTarget: 'umd',
+            library: {
+                root: settings.build.processDeclaration.moduleName.split("."),
+                amd: settings.build.processDeclaration.packageName,
+                commonjs: settings.build.processDeclaration.packageName
+            },
+            umdNamedDefine: true
+        },
+        resolve: {
+            extensions: [".ts", ...options.resolveExtensions]
+        },
+        externals: [babylonExternals()],
+        devtool: "none",
+        module: {
+            rules: [{
+                test: /\.tsx?$/,
+                loader: 'awesome-typescript-loader',
+                options: {
+                    configFileName: path.resolve(webpackFolder, './tsconfig.json'),
+                    declaration: false
+                }
+            }]
+        },
+        mode: "production",
+        performance: {
+            hints: false
+        },
+        plugins: [
+            new hardSourceWebpackPlugin(),
+            new webpack.WatchIgnorePlugin([
+                /\.js$/,
+                /\.d\.ts$/,
+                /\.fx$/
+            ])
+        ]
+    }
+};

+ 6 - 46
src/webpack.config.js

@@ -1,47 +1,7 @@
-const path = require('path');
-const webpack = require('webpack');
-const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
+const babylonWebpackConfig = require('../Tools/WebpackPlugins/babylonWebpackConfig');
 
-module.exports = {
-    context: __dirname,
-    entry: {
-        'babylonjs': path.resolve(__dirname, './Legacy/legacy.ts'),
-    },
-    output: {
-        path: path.resolve(__dirname, '../dist/preview release'),
-        filename: 'babylon.js',
-        libraryTarget: 'umd',
-        library: {
-            root: ["BABYLON"],
-            amd: "babylonjs",
-            commonjs: "babylonjs"
-        },
-        umdNamedDefine: true
-    },
-    resolve: {
-        extensions: ['.ts']
-    },
-    devtool: "source-map",
-    module: {
-        rules: [{
-            test: /\.tsx?$/,
-            loader: 'awesome-typescript-loader',
-            options: {
-                configFileName: path.resolve(__dirname, './tsconfig.json'),
-                declaration: false
-            }
-        }]
-    },
-    mode: "production",
-    performance: {
-        hints: false
-    },
-    plugins: [
-        new HardSourceWebpackPlugin(),
-        new webpack.WatchIgnorePlugin([
-            /\.js$/,
-            /\.d\.ts$/,
-            /\.fx$/
-        ])
-    ]
-}
+var config = babylonWebpackConfig({
+    module: "core"
+});
+
+module.exports = config;