UNPKG

@nx/rspack

Version:

The Nx Plugin for Rspack contains executors and generators that support building applications using Rspack.

45 lines (44 loc) 1.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.withWeb = withWeb; const apply_web_config_1 = require("../plugins/utils/apply-web-config"); const processed = new Set(); function withWeb(pluginOptions = {}) { return function makeConfig(config, { options, context }) { if (processed.has(config)) { return config; } (0, apply_web_config_1.applyWebConfig)({ ...options, ...pluginOptions, root: context.root, projectName: context.projectName, targetName: context.targetName, configurationName: context.configurationName, projectGraph: context.projectGraph, useLegacyHtmlPlugin: pluginOptions.useLegacyHtmlPlugin ?? false, }, config); processed.add(config); return config; }; } function getClientEnvironment(mode) { // Grab NODE_ENV and NX_PUBLIC_* environment variables and prepare them to be // injected into the application via DefinePlugin in rspack configuration. const nxPublicKeyRegex = /^NX_PUBLIC_/i; const raw = Object.keys(process.env) .filter((key) => nxPublicKeyRegex.test(key)) .reduce((env, key) => { env[key] = process.env[key]; return env; }, {}); // Stringify all values so we can feed into rspack DefinePlugin const stringified = Object.keys(raw).reduce((env, key) => { env[`process.env.${key}`] = JSON.stringify(raw[key]); return env; }, // Provide a fallback for process.env itself to handle cases where code // accesses process.env directly (e.g., in Cypress component testing) { 'process.env': '({})' }); return { stringified }; }