Skip to content

Commit

Permalink
chore(shared): remove setConfig helper (#1405)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan committed Jan 23, 2024
1 parent e2e2f08 commit e2933ad
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
10 changes: 6 additions & 4 deletions packages/core/src/provider/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
CSS_REGEX,
CSS_MODULES_REGEX,
getCssLoaderOptions,
setConfig,
getPostcssLoaderOptions,
getCssModuleLocalIdentName,
resolvePackage,
Expand Down Expand Up @@ -227,7 +226,8 @@ export const pluginCss = (): RsbuildPlugin => {
const config = api.getNormalizedConfig();

if (!enableNativeCss(config)) {
setConfig(rspackConfig, 'experiments.css', false);
rspackConfig.experiments ||= {};
rspackConfig.experiments.css = false;
return;
}

Expand All @@ -244,11 +244,13 @@ export const pluginCss = (): RsbuildPlugin => {
}

// need use type: "css/module" rule instead of modules.auto config
setConfig(rspackConfig, 'builtins.css.modules', {
rspackConfig.builtins ||= {};
rspackConfig.builtins.css ||= {};
rspackConfig.builtins.css.modules = {
localsConvention: config.output.cssModules.exportLocalsConvention,
localIdentName,
exportsOnly: isServer || isWebWorker,
});
};

const rules = rspackConfig.module?.rules;

Expand Down
13 changes: 5 additions & 8 deletions packages/core/src/provider/plugins/resolve.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { RsbuildPlugin } from '../../types';
import { setConfig, applyResolvePlugin } from '@rsbuild/shared';
import { applyResolvePlugin } from '@rsbuild/shared';

export const pluginResolve = (): RsbuildPlugin => ({
name: 'rsbuild:resolve',
Expand All @@ -11,21 +11,18 @@ export const pluginResolve = (): RsbuildPlugin => ({
const isTsProject = Boolean(api.context.tsconfigPath);
const config = api.getNormalizedConfig();

rspackConfig.resolve ||= {};

if (isTsProject && config.source.aliasStrategy === 'prefer-tsconfig') {
setConfig(
rspackConfig,
'resolve.tsConfigPath',
api.context.tsconfigPath,
);
rspackConfig.resolve.tsConfigPath = api.context.tsconfigPath;
}

if (isServer) {
// FIXME:
// When targe = node, we no need to specify conditionsNames.
// We guess the webpack would auto specify reference to target.
// Rspack has't the action, so we need manually specify.
const nodeConditionNames = ['require', 'node'];
setConfig(rspackConfig, 'resolve.conditionNames', nodeConditionNames);
rspackConfig.resolve.conditionNames = ['require', 'node'];
}
});
},
Expand Down
9 changes: 0 additions & 9 deletions packages/shared/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import type { minify } from 'terser';
import fse from '../compiled/fs-extra';
import { pick, color, upperFirst } from './utils';

import _ from 'lodash';
import { DEFAULT_DEV_HOST } from './constants';
import { getTerserMinifyOptions } from './minimize';

Expand Down Expand Up @@ -220,14 +219,6 @@ export type GetTypeByPath<
? GetTypeByPath<P, K extends '' ? C : NonNullable<C[K]>>
: C[T];

export const setConfig = <T extends Record<string, any>, P extends string>(
config: T,
path: P,
value: GetTypeByPath<P, T>,
) => {
_.set(config, path, value);
};

type MinifyOptions = NonNullable<Parameters<typeof minify>[1]>;

export async function getMinify(isProd: boolean, config: NormalizedConfig) {
Expand Down

0 comments on commit e2933ad

Please sign in to comment.