UNPKG

@nx/angular

Version:

The Nx Plugin for Angular contains executors, generators, and utilities for managing Angular applications and libraries within an Nx workspace. It provides: - Integration with libraries such as Storybook, Jest, ESLint, Tailwind CSS, Playwright and Cypre

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 (!isWebpackBrowserUsed(tree)) { return; } ensureTargetDefaultsContainProductionInputs(tree); await (0, devkit_1.formatFiles)(tree); } function ensureTargetDefaultsContainProductionInputs(tree) { const nxJson = (0, devkit_1.readNxJson)(tree); const webpackExecutor = '@nx/angular:webpack-browser'; 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 isWebpackBrowserUsed(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/angular:webpack-browser' && (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; }