Webpack - how to determine which project is target for build in webpack

Viewed 465

I am building new project based on Monorepo/NX(nrwl) and micro front-end architecture. I have extracted webpack config to build angular projects. there might be several angular projects and using nx command nx build [target] I do builds.

Inside webpack config, I use return function according to a lot of custom operations. in function two parameters are sent config and options. Instead having separated package.json for each project in monorepo, there is one shared file known as workspace.json and it includes all configs. So when i run nx build [target] it goes to workspace.json, looks for corresponding project and runs builders.

According to custom webpack configurations, firs problem was that all main.js builds had webpackJsonp key in global object and because i load several micro apps as web components, they had the same key (webpackJsonp) and override each other. But i fixed that with this line of code

config.output.jsonpFunction = 'webpackJsonp_' + Math.random().toString(36).substring(7);

But now, i want to run several shell commands to merge bundles as one bundle and move merged bundle to the directory where my bootstraper lives.

Because all bundles are stored inside dist folder with separated folders automatically by nx, i would like to access that folders from custom webpack config to be able to move them into another destination. all sub folders in dist have the same name as projects have. for example if i have project header, after build there is dist/header/ folder and builds are stored there.

I do not want to pass parameters like this nx build [name] --additiona params. I want to somehow know inside custom.webpack.js file during build which project builds web pack.

0 Answers
Related