Skip to content

Commit afc3288

Browse files
authored
Merge pull request #387 from izaera/LPS-126503
feat: allow extension of webpack `exposes`
2 parents 6252b50 + 678a34e commit afc3288

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

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

Lines changed: 25 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+
...transformExposes(exposes, build.input),
223229
'.': mainFilePath,
224230
},
225231
filename: 'container.js',
@@ -256,3 +262,21 @@ module.exports = async function () {
256262
},
257263
};
258264
};
265+
266+
function transformExposes(exposes, inputDir) {
267+
return exposes.reduce((exposes, filePath) => {
268+
if (!filePath.startsWith('<inputDir>/')) {
269+
throw new Error(
270+
"Only paths relative to '<inputDir>/' are accepted as 'exposes'"
271+
);
272+
}
273+
274+
filePath = filePath.replace(/^<inputDir>\//, '');
275+
276+
const exposeName = filePath.replace(/\.js$/i, '');
277+
278+
exposes[exposeName] = `./${inputDir}/${filePath}`;
279+
280+
return exposes;
281+
}, {});
282+
}

0 commit comments

Comments
 (0)