"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var src_exports = {}; __export(src_exports, { PLUGIN_LESS_NAME: () => PLUGIN_LESS_NAME, pluginLess: () => pluginLess }); module.exports = __toCommonJS(src_exports); var import_node_path = __toESM(require("path")); var import_deepmerge = __toESM(require("deepmerge")); var import_reduce_configs = require("reduce-configs"); var PLUGIN_LESS_NAME = "rsbuild:less"; var getLessLoaderOptions = (userOptions, isUseCssSourceMap, rootPath) => { const excludes = []; const addExcludes = (items) => { excludes.push(...Array.isArray(items) ? items : [items]); }; const defaultLessLoaderOptions = { lessOptions: { javascriptEnabled: true, // let less resolve from node_modules in the current root directory, // Avoid resolving from wrong node_modules. paths: [import_node_path.default.join(rootPath, "node_modules")] }, sourceMap: isUseCssSourceMap, implementation: import_node_path.default.join(__dirname, "../compiled/less/index.js") }; const mergeFn = (defaults, userOptions2) => { const getLessOptions = () => { if (defaults.lessOptions && userOptions2.lessOptions) { return (0, import_deepmerge.default)(defaults.lessOptions, userOptions2.lessOptions); } return userOptions2.lessOptions || defaults.lessOptions; }; return { ...defaults, ...userOptions2, lessOptions: getLessOptions() }; }; const mergedOptions = (0, import_reduce_configs.reduceConfigsWithContext)({ initial: defaultLessLoaderOptions, config: userOptions, ctx: { addExcludes }, mergeFn }); return { options: mergedOptions, excludes }; }; var pluginLess = (pluginOptions = {}) => ({ name: PLUGIN_LESS_NAME, setup(api) { api.modifyBundlerChain(async (chain, { CHAIN_ID, environment }) => { const { config } = environment; const rule = chain.module.rule(CHAIN_ID.RULE.LESS).test(/\.less$/).merge({ sideEffects: true }).resolve.preferRelative(true).end(); const { excludes, options } = getLessLoaderOptions( pluginOptions.lessLoaderOptions, config.output.sourceMap.css, api.context.rootPath ); for (const item of excludes) { rule.exclude.add(item); } if (pluginOptions.exclude) { rule.exclude.add(pluginOptions.exclude); } const cssRule = chain.module.rules.get(CHAIN_ID.RULE.CSS); for (const id of Object.keys(cssRule.uses.entries())) { const loader = cssRule.uses.get(id); const options2 = loader.get("options") ?? {}; const clonedOptions = (0, import_deepmerge.default)({}, options2); if (id === CHAIN_ID.USE.CSS) { clonedOptions.importLoaders += 1; } rule.use(id).loader(loader.get("loader")).options(clonedOptions); } rule.use(CHAIN_ID.USE.LESS).loader(import_node_path.default.join(__dirname, "../compiled/less-loader/index.js")).options(options); }); } }); // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { PLUGIN_LESS_NAME, pluginLess });