UNPKG

@nx/react

Version:

The React plugin for Nx contains executors and generators for managing React applications and libraries within an Nx workspace. It provides: - Integration with libraries such as Jest, Vitest, Playwright, Cypress, and Storybook. - Generators for applica

54 lines (53 loc) 2.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = default_1; const devkit_1 = require("@nx/devkit"); async function default_1(tree) { if (!hasModuleFederationProject(tree)) { return; } ensureTargetDefaultsContainProductionInputs(tree); await (0, devkit_1.formatFiles)(tree); } function ensureTargetDefaultsContainProductionInputs(tree) { const nxJson = (0, devkit_1.readNxJson)(tree); const webpackExecutor = '@nx/webpack:webpack'; const mfEnvVar = 'NX_MF_DEV_SERVER_STATIC_REMOTES'; nxJson.targetDefaults[webpackExecutor] ??= {}; nxJson.targetDefaults[webpackExecutor].inputs ??= [ 'production', '^production', { env: mfEnvVar }, ]; if (!nxJson.targetDefaults[webpackExecutor].inputs.includes('production')) { nxJson.targetDefaults[webpackExecutor].inputs.push('production'); } if (!nxJson.targetDefaults[webpackExecutor].inputs.includes('^production')) { nxJson.targetDefaults[webpackExecutor].inputs.push('^production'); } let mfEnvVarExists = false; for (const input of nxJson.targetDefaults[webpackExecutor].inputs) { if (typeof input === 'object' && input['env'] === mfEnvVar) { mfEnvVarExists = true; break; } } if (!mfEnvVarExists) { nxJson.targetDefaults[webpackExecutor].inputs.push({ env: mfEnvVar }); } (0, devkit_1.updateNxJson)(tree, nxJson); } function hasModuleFederationProject(tree) { const projects = (0, devkit_1.getProjects)(tree); for (const project of projects.values()) { const targets = project.targets || {}; for (const [_, target] of Object.entries(targets)) { if (target.executor === '@nx/webpack:webpack' && (tree.exists((0, devkit_1.joinPathFragments)(project.root, 'module-federation.config.ts')) || tree.exists((0, devkit_1.joinPathFragments)(project.root, 'module-federation.config.js')))) { return true; } } } return false; }