From 4a5559b2037e0cd5a99f655ee1e32e7d6b2a090a Mon Sep 17 00:00:00 2001 From: Ivo Branco Date: Fri, 11 Apr 2025 18:30:16 +0100 Subject: [PATCH 1/2] feat(formatjs): support additional src folders (#650) --- bin/fedx-scripts.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/bin/fedx-scripts.js b/bin/fedx-scripts.js index d3257831d..ad8079811 100755 --- a/bin/fedx-scripts.js +++ b/bin/fedx-scripts.js @@ -69,11 +69,32 @@ switch (commandName) { require('webpack-dev-server/bin/webpack-dev-server'); break; case 'formatjs': { + // The include option is used to specify which additional source folders to extract messages from. + // To extract more messages on other source folders use: --include=plugins --include=plugins2 + // The intention use case is to allow extraction from the 'plugins' directory on 'frontend-app-authoring'. + // That plugins folder were kept outside the src folder to ensure they remain independent and + // can function without relying on the MFE environment's special features. + // This approach allows them to be packaged separately as NPM packages. + const additionalSrcFolders = []; + process.argv.forEach((val, index) => { + // if val starts with --include= then add the value to additionalSrcFolders + if (val.startsWith('--include=')) { + additionalSrcFolders.push(val.split('=')[1]); + // remove the value from process.argv + process.argv.splice(index, 1); + } + }); + const srcFolders = ['src'].concat(additionalSrcFolders); + let srcFoldersString = srcFolders.join(','); + if (srcFolders.length > 1) { + srcFoldersString = `{${srcFoldersString}}`; + } const commonArgs = [ '--format', 'node_modules/@openedx/frontend-build/lib/formatter.js', - '--ignore', 'src/**/*.json', + '--ignore', `${srcFoldersString}/**/*.json`, + '--ignore', `${srcFoldersString}/**/*.d.ts`, '--out-file', './temp/babel-plugin-formatjs/Default.messages.json', - '--', 'src/**/*.js*', + '--', `${srcFoldersString}/**/*.{j,t}s*`, ]; process.argv = process.argv.concat(commonArgs); ensureConfigOption(presets.formatjs); From e3856b0fab23dd271e6f018103f94bae36080421 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Behmo?= Date: Tue, 1 Apr 2025 12:44:18 +0200 Subject: [PATCH 2/2] feat: lighter build by rewriting lodash imports Incorrect lodash imports are causing MFEs to import the entire lodash library. This change shaves off a few kB of every MFE compressed build. --- config/babel.config.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/config/babel.config.js b/config/babel.config.js index 2c0e1424d..8cd8743e6 100644 --- a/config/babel.config.js +++ b/config/babel.config.js @@ -12,8 +12,12 @@ module.exports = { '@babel/plugin-proposal-class-properties', '@babel/plugin-syntax-dynamic-import', [ + // Prevent importing large libraries by rewriting imports + // Eventually, we should add 'preventFullImport": true' to each of these imports, + // to prevent developers from committing full imports. 'transform-imports', { + // fortawesome '@fortawesome/free-brands-svg-icons': { transform: '@fortawesome/free-brands-svg-icons/${member}', skipDefaultConversion: true, @@ -26,6 +30,11 @@ module.exports = { transform: '@fortawesome/free-solid-svg-icons/${member}', skipDefaultConversion: true, }, + // lodash + lodash: { + transform: 'lodash/${member}', + skipDefaultConversion: true, + }, }, ], ],