Skip to content

Commit c80eddf

Browse files
committed
feat(npm-tools): allow extension of webpack exposes
This is needed for LPS-126503 because we need to export JS endpoint to be consumed from <react:component>.
1 parent 6252b50 commit c80eddf

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

projects/npm-tools/packages/npm-scripts/src/utils/createFederationConfig.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,13 @@ module.exports = async function () {
179179

180180
await writeWebpackFederationEntryPoint(mainFilePath);
181181

182-
let {remotes, shared} = getMergedConfig('npmscripts', 'federation');
182+
const config = getMergedConfig('npmscripts');
183183

184+
const {build, federation} = config;
185+
186+
let {exposes, remotes, shared} = federation;
187+
188+
exposes = exposes || [];
184189
remotes = remotes || [];
185190
shared = shared || [];
186191

@@ -220,6 +225,7 @@ module.exports = async function () {
220225
plugins: [
221226
new ModuleFederationPlugin({
222227
exposes: {
228+
...prefixExposesPaths(exposes, `./${build.input}/`),
223229
'.': mainFilePath,
224230
},
225231
filename: 'container.js',
@@ -256,3 +262,15 @@ module.exports = async function () {
256262
},
257263
};
258264
};
265+
266+
function prefixExposesPaths(exposes, prefix) {
267+
return exposes.reduce((exposes, filePath) => {
268+
const exposeName = path.posix
269+
.relative('.', filePath)
270+
.replace(/\.js$/i, '');
271+
272+
exposes[exposeName] = `${prefix}${filePath}`;
273+
274+
return exposes;
275+
}, {});
276+
}

0 commit comments

Comments
 (0)