@nx/rspack
Version:
53 lines (52 loc) • 2.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.withWeb = withWeb;
const apply_web_config_1 = require("../plugins/utils/apply-web-config");
const deprecation_1 = require("./deprecation");
const processed = new Set();
/**
* @deprecated Will be removed in Nx v24. Use `NxAppRspackPlugin` from
* `@nx/rspack/app-plugin` in a standard rspack config and run
* `nx g @nx/rspack:convert-to-inferred`. See
* https://nx.dev/docs/guides/tasks--caching/convert-to-inferred for details.
*/
function withWeb(pluginOptions = {}) {
(0, deprecation_1.warnRspackComposeHelpersDeprecation)();
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 };
}