From 35413607c62f2de2a90941d487b7964b5c213999 Mon Sep 17 00:00:00 2001 From: Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> Date: Tue, 4 Apr 2023 18:45:18 +0530 Subject: Arranging shared modules in the scripts in order to make sure that the dependencies are available when shared modules references each other. --- .../webpack/loader/arrange-shared-module-loader.js | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 config/webpack/loader/arrange-shared-module-loader.js (limited to 'config/webpack/loader') diff --git a/config/webpack/loader/arrange-shared-module-loader.js b/config/webpack/loader/arrange-shared-module-loader.js new file mode 100644 index 0000000..9e21b23 --- /dev/null +++ b/config/webpack/loader/arrange-shared-module-loader.js @@ -0,0 +1,26 @@ +const path = require("path"); + +const { ImportManager } = require("import-manager"); + +const sharedModules = webpackRequire("utils/shared-modules.js"); + +module.exports = function(source) { + const { sortedSharedModules } = this.getOptions(); + const manager = new ImportManager(source); + + for (const unit of manager.imports.es6.units) { + const moduleIndex = sharedModules.indexOf(unit.module.name); + + if (moduleIndex >= 0) { + const currentSharedModuleName = sharedModules[moduleIndex]; + + if (!sortedSharedModules.includes(currentSharedModuleName)) { + sortedSharedModules.push(currentSharedModuleName); + } + } + } + + sortedSharedModules.push(path.basename(this.resourcePath.substring(0, this.resourcePath.length - 3))); + + return source; +}; -- cgit v1.2.3