Properly remove lazy-loaded modules from the bundle
authorAlexander Ebert <ebert@woltlab.com>
Thu, 27 Jan 2022 18:53:06 +0000 (19:53 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 27 Jan 2022 18:53:06 +0000 (19:53 +0100)
wcfsetup/install/files/js/require.build.js

index cbec15a255d9910042ebba24464d540165de43a3..6b2cd553849ca7a4a5983ab639f4cef3d432cb11 100644 (file)
@@ -1,4 +1,6 @@
 (function () {
+       const excludedModules = [];
+
        var config = {
                mainConfigFile: 'require.config.js',
                generateSourceMaps: true,
@@ -69,6 +71,7 @@
                                        if ((matches = contents.match(/@woltlabExcludeBundle\s+(tiny|all)/))) {
                                                switch (matches[1]) {
                                                        case 'all':
+                                                               excludedModules.push(module.replace(/\.js$/, ''));
                                                                return false;
                                                        case 'tiny':
                                                                return moduleName !== 'WoltLabSuite.Core.tiny.min';
                        }
                        
                        return moduleContents;
-               }
+               },
+               onBuildWrite(moduleName, path, contents) {
+                       if (excludedModules.includes(moduleName)) {
+                               return "";
+                       }
+                       
+                       return contents;
+               },
        };
        
        var _isSupportedBuildUrl = require._isSupportedBuildUrl;