Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(plugin-less): lessLoaderOptions.lessOptions.plugins has lose it's prototype. #3815

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/core/src/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ export {
} from './config';
export type { InternalContext } from './types';
export { setHTMLPlugin, getHTMLPlugin } from './pluginHelper';
export { formatStats, getStatsOptions, prettyTime } from './helpers';
export {
formatStats,
getStatsOptions,
prettyTime,
isPlainObject,
} from './helpers';
export { registerBuildHook, registerDevHook, onCompileDone } from './hooks';
export { getChainUtils, getConfigUtils } from './provider/rspackConfig';
export { chainToConfig, modifyBundlerChain } from './configChain';
Expand Down
5 changes: 4 additions & 1 deletion packages/plugin-less/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
RsbuildPlugin,
Rspack,
} from '@rsbuild/core';
import { __internalHelper } from '@rsbuild/core';
import deepmerge from 'deepmerge';
import { reduceConfigsWithContext } from 'reduce-configs';

Expand Down Expand Up @@ -75,7 +76,9 @@ const getLessLoaderOptions = (
): LessLoaderOptions => {
const getLessOptions = () => {
if (defaults.lessOptions && userOptions.lessOptions) {
return deepmerge(defaults.lessOptions, userOptions.lessOptions);
return deepmerge(defaults.lessOptions, userOptions.lessOptions, {
isMergeableObject: __internalHelper.isPlainObject,
});
}
return userOptions.lessOptions || defaults.lessOptions;
};
Expand Down
60 changes: 60 additions & 0 deletions packages/plugin-less/tests/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,66 @@ exports[`plugin-less > should add less-loader with excludes 1`] = `
]
`;

exports[`plugin-less > should add less-loader with plugins 1`] = `
[
{
"resolve": {
"preferRelative": true,
},
"sideEffects": true,
"test": /\\\\\\.less\\$/,
"use": [
{
"loader": "<ROOT>/node_modules/<PNPM_INNER>/@rspack/core/dist/cssExtractLoader.js",
},
{
"loader": "<ROOT>/packages/core/compiled/css-loader/index.js",
"options": {
"importLoaders": 2,
"modules": {
"auto": true,
"exportGlobals": false,
"exportLocalsConvention": "camelCase",
"localIdentName": "[path][name]__[local]-[hash:base64:6]",
"namedExport": false,
},
"sourceMap": false,
},
},
{
"loader": "builtin:lightningcss-loader",
"options": {
"targets": [
"chrome >= 87",
"edge >= 88",
"firefox >= 78",
"safari >= 14",
],
},
},
{
"loader": "<ROOT>/packages/plugin-less/compiled/less-loader/index.js",
"options": {
"implementation": "<ROOT>/packages/plugin-less/compiled/less/index.js",
"lessOptions": {
"javascriptEnabled": true,
"paths": [
"<ROOT>/node_modules",
],
"plugins": [
{
"options": undefined,
},
],
},
"sourceMap": false,
},
},
],
},
]
`;

exports[`plugin-less > should add less-loader with tools.less 1`] = `
[
{
Expand Down
26 changes: 26 additions & 0 deletions packages/plugin-less/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,30 @@ describe('plugin-less', () => {
const bundlerConfigs = await rsbuild.initConfigs();
expect(matchRules(bundlerConfigs[0], 'a.less')).toMatchSnapshot();
});

it('should add less-loader with plugins', async () => {
class MockPlugin {
options?: any;
constructor(options?: any) {
this.options = options;
}
install(less: any, pluginManager: any) {}
}
const mockPlugin = new MockPlugin();
const rsbuild = await createRsbuild({
rsbuildConfig: {
plugins: [
pluginLess({
lessLoaderOptions: {
lessOptions: {
plugins: [mockPlugin],
},
},
}),
],
},
});
const bundlerConfigs = await rsbuild.initConfigs();
expect(matchRules(bundlerConfigs[0], 'a.less')).toMatchSnapshot();
});
});