@nx/rspack
Version:
54 lines (53 loc) • 2.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.NxAppRspackPlugin = void 0;
const normalize_options_1 = require("../utils/plugins/normalize-options");
const apply_base_config_1 = require("../utils/apply-base-config");
const apply_web_config_1 = require("../utils/apply-web-config");
/**
* This plugin provides features to build Node and Web applications.
* - TS Support (including tsconfig paths
* - Assets handling
* - Stylesheets handling
* - index.html and package.json generation
*
* Web-only features, such as stylesheets and images, are only supported when `target` is `web` or `webworker`.
*/
class NxAppRspackPlugin {
constructor(options = {}) {
// If we're building inferred targets, skip normalizing the build options
if (!global.NX_GRAPH_CREATION) {
this.options = (0, normalize_options_1.normalizeOptions)(options);
}
}
apply(compiler) {
// Default's to web
const target = this.options.target ?? compiler.options.target;
this.options.outputPath ??= compiler.options.output?.path;
if (typeof target === 'string') {
this.options.target = target;
}
if (compiler.options.entry &&
compiler.options.entry['main'] &&
typeof compiler.options.entry['main'] === 'object' &&
Object.keys(compiler.options.entry['main']).length === 0) {
compiler.options.entry = {};
}
// Prefer `clean` option from Rspack config over our own.
if (typeof compiler.options.output.clean !== 'undefined') {
this.options.deleteOutputPath = false;
}
(0, apply_base_config_1.applyBaseConfig)(this.options, compiler.options, {
useNormalizedEntry: true,
});
if (compiler.options.target) {
this.options.target = compiler.options.target;
}
if (this.options.target === 'web' || this.options.target === 'webworker') {
(0, apply_web_config_1.applyWebConfig)(this.options, compiler.options, {
useNormalizedEntry: true,
});
}
}
}
exports.NxAppRspackPlugin = NxAppRspackPlugin;