Skip to content

Commit

Permalink
docs: replace bundler-chain with rspack-chain (#2533)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan committed Jun 6, 2024
1 parent ed4f2f5 commit e7e90ea
Show file tree
Hide file tree
Showing 31 changed files with 91 additions and 106 deletions.
4 changes: 2 additions & 2 deletions e2e/cases/inline-chunk/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import path from 'node:path';
import { build, gotoPage } from '@e2e/helper';
import { expect, test } from '@playwright/test';
import type { BundlerChain } from '@rsbuild/shared';
import type { RspackChain } from '@rsbuild/shared';

// use source-map for easy to test. By default, Rsbuild use hidden-source-map
const toolsConfig = {
bundlerChain: (chain: BundlerChain) => {
bundlerChain: (chain: RspackChain) => {
chain.devtool('source-map');
},
htmlPlugin: (config: any) => {
Expand Down
6 changes: 3 additions & 3 deletions packages/compat/webpack/src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import fs from 'node:fs';
import {
type BundlerChain,
type ChainIdentifier,
type CopyPluginOptions,
type RsbuildPlugin,
type RsbuildTarget,
type RspackChain,
TARGET_ID_MAP,
isWebTarget,
} from '@rsbuild/shared';
Expand All @@ -16,7 +16,7 @@ async function applyTsConfigPathsPlugin({
extensions,
configFile,
}: {
chain: BundlerChain;
chain: RspackChain;
CHAIN_ID: ChainIdentifier;
mainFields: (string | string[])[];
extensions: string[];
Expand All @@ -36,7 +36,7 @@ async function applyTsConfigPathsPlugin({
]);
}

const getMainFields = (chain: BundlerChain, target: RsbuildTarget) => {
const getMainFields = (chain: RspackChain, target: RsbuildTarget) => {
const mainFields = chain.resolve.mainFields.values();

if (mainFields.length) {
Expand Down
5 changes: 1 addition & 4 deletions packages/compat/webpack/src/webpackConfig.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { __internalHelper } from '@rsbuild/core';
import {
type BundlerChain,
type ModifyWebpackChainUtils,
type ModifyWebpackConfigUtils,
type RsbuildTarget,
Expand Down Expand Up @@ -162,9 +161,7 @@ export async function generateWebpackConfig({

const chain = await modifyWebpackChain(context, chainUtils, bundlerChain);

let webpackConfig = chainToConfig(
chain as unknown as BundlerChain,
) as WebpackConfig;
let webpackConfig = chainToConfig(chain) as WebpackConfig;

webpackConfig = await modifyWebpackConfig(
context,
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import path from 'node:path';
import {
type BundlerChain,
DEFAULT_ASSET_PREFIX,
type MultiStats,
type RspackChain,
type Stats,
type StatsError,
addTrailingSlash,
Expand Down Expand Up @@ -232,7 +232,7 @@ export const formatPublicPath = (publicPath: string, withSlash = true) => {
};

export const getPublicPathFromChain = (
chain: BundlerChain,
chain: RspackChain,
withSlash = true,
) => {
const publicPath = chain.output.get('publicPath');
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export type {
CrossOrigin,
ConsoleType,
SplitChunks,
BundlerChain,
RspackChain,
ClientConfig,
ScriptInject,
ConfigChain,
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/initPlugins.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { join } from 'node:path';
import {
type BundlerChain,
type GetRsbuildConfig,
type PluginManager,
type RsbuildPluginAPI,
type RspackChain,
type TransformFn,
type TransformHandler,
getDistPath,
Expand All @@ -28,7 +28,7 @@ export function getHTMLPathByEntry(
}

function applyTransformPlugin(
chain: BundlerChain,
chain: RspackChain,
transformer: Record<string, TransformHandler>,
) {
const name = 'RsbuildTransformPlugin';
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/plugins/resolve.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
type BundlerChain,
type ChainIdentifier,
type NormalizedConfig,
type RsbuildTarget,
type RspackChain,
castArray,
reduceConfigsWithContext,
} from '@rsbuild/shared';
Expand All @@ -15,7 +15,7 @@ function applyFullySpecified({
chain,
CHAIN_ID,
}: {
chain: BundlerChain;
chain: RspackChain;
config: NormalizedConfig;
CHAIN_ID: ChainIdentifier;
}) {
Expand All @@ -25,7 +25,7 @@ function applyFullySpecified({
.resolve.set('fullySpecified', false);
}

function applyExtensions({ chain }: { chain: BundlerChain }) {
function applyExtensions({ chain }: { chain: RspackChain }) {
const extensions = [
// most projects are using TypeScript, resolve .ts(x) files first to reduce resolve time.
'.ts',
Expand All @@ -45,7 +45,7 @@ function applyAlias({
config,
rootPath,
}: {
chain: BundlerChain;
chain: RspackChain;
target: RsbuildTarget;
config: NormalizedConfig;
rootPath: string;
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/plugins/swc.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import path from 'node:path';
import {
type BundlerChain,
type Polyfill,
type RsbuildTarget,
type RspackChain,
SCRIPT_REGEX,
applyScriptCondition,
cloneDeep,
Expand Down Expand Up @@ -143,7 +143,7 @@ export const pluginSwc = (): RsbuildPlugin => ({

async function applyCoreJs(
swcConfig: SwcLoaderOptions,
chain: BundlerChain,
chain: RspackChain,
polyfillMode: Polyfill,
) {
const coreJsPath = require.resolve('core-js/package.json');
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-babel/src/helper.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { isAbsolute, normalize, sep } from 'node:path';
import type { PluginOptions as BabelPluginOptions } from '@babel/core';
import type {
BundlerChain,
ChainIdentifier,
NormalizedConfig,
RspackChain,
} from '@rsbuild/core';
import { castArray, reduceConfigsWithContext } from '@rsbuild/shared';
import upath from 'upath';
Expand Down Expand Up @@ -182,7 +182,7 @@ export const modifyBabelLoaderOptions = ({
CHAIN_ID,
modifier,
}: {
chain: BundlerChain;
chain: RspackChain;
CHAIN_ID: ChainIdentifier;
modifier: (config: BabelTransformOptions) => BabelTransformOptions;
}) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-css-minimizer/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type {
BundlerChain,
ChainIdentifier,
ConfigChain,
RsbuildPlugin,
RspackChain,
} from '@rsbuild/core';
import { reduceConfigs } from '@rsbuild/shared';
import CssMinimizerWebpackPlugin from 'css-minimizer-webpack-plugin';
Expand Down Expand Up @@ -37,7 +37,7 @@ const getCssnanoDefaultOptions = (): CssNanoOptions => ({
});

export function applyCSSMinimizer(
chain: BundlerChain,
chain: RspackChain,
CHAIN_ID: ChainIdentifier,
options: PluginCssMinimizerOptions = {},
) {
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-lightningcss/src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import path from 'node:path';
import type {
BundlerChain,
ChainIdentifier,
NormalizedConfig,
RsbuildContext,
RsbuildPlugin,
RsbuildTarget,
RspackChain,
} from '@rsbuild/core';
import { getBrowserslistWithDefault, reduceConfigs } from '@rsbuild/shared';
import browserslist from '@rsbuild/shared/browserslist';
Expand Down Expand Up @@ -53,7 +53,7 @@ const applyLightningCSSLoader = ({
targets,
options = {},
}: {
chain: BundlerChain;
chain: RspackChain;
CHAIN_ID: ChainIdentifier;
targets: Targets;
options: PluginLightningcssOptions | undefined;
Expand Down Expand Up @@ -97,7 +97,7 @@ const applyLightningCSSMinifyPlugin = async ({
targets,
options,
}: {
chain: BundlerChain;
chain: RspackChain;
CHAIN_ID: ChainIdentifier;
targets: Targets;
options: PluginLightningcssOptions | undefined;
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-react/src/react.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import path from 'node:path';
import type {
BundlerChain,
ChainIdentifier,
RsbuildConfig,
RsbuildPluginAPI,
Rspack,
RspackChain,
} from '@rsbuild/core';
import { SCRIPT_REGEX, deepmerge, isUsingHMR } from '@rsbuild/shared';
import type { PluginReactOptions } from '.';
Expand All @@ -14,7 +14,7 @@ const modifySwcLoaderOptions = ({
CHAIN_ID,
modifier,
}: {
chain: BundlerChain;
chain: RspackChain;
CHAIN_ID: ChainIdentifier;
modifier: (config: Rspack.SwcLoaderOptions) => Rspack.SwcLoaderOptions;
}) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-source-build/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export function pluginSourceBuild(
: ['...', sourceField],
);

// bundler-chain do not support resolve.conditionNames yet
// rspack-chain do not support resolve.conditionNames yet
rule.resolve.merge({
// `conditionNames` is not affected by `resolvePriority`.
// The priority is controlled by the order of fields declared in `exports`.
Expand Down
9 changes: 4 additions & 5 deletions packages/shared/src/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { EntryDescription } from '@rspack/core';
import { NODE_MODULES_REGEX, TS_AND_JSX_REGEX } from './constants';
import { debug } from './logger';
import type {
BundlerChain,
CreateAsyncHook,
ModifyBundlerChainFn,
ModifyBundlerChainUtils,
Expand All @@ -23,7 +22,7 @@ export async function getBundlerChain() {

const bundlerChain = new RspackChain();

return bundlerChain as unknown as BundlerChain;
return bundlerChain as unknown as RspackChain;
}

export async function modifyBundlerChain(
Expand All @@ -34,7 +33,7 @@ export async function modifyBundlerChain(
config: Readonly<RsbuildConfig>;
},
utils: ModifyBundlerChainUtils,
): Promise<BundlerChain> {
): Promise<RspackChain> {
debug('modify bundler chain');

const bundlerChain = await getBundlerChain();
Expand Down Expand Up @@ -236,7 +235,7 @@ export function applyScriptCondition({
excludes,
}: {
rule: RspackChain.Rule;
chain: BundlerChain;
chain: RspackChain;
config: NormalizedConfig;
context: RsbuildContext;
includes: (string | RegExp)[];
Expand Down Expand Up @@ -269,7 +268,7 @@ export function applyScriptCondition({
}
}

export function chainToConfig(chain: BundlerChain): RspackConfig {
export function chainToConfig(chain: RspackChain): RspackConfig {
const config = chain.toConfig();
const { entry } = config;

Expand Down
11 changes: 0 additions & 11 deletions packages/shared/src/types/bundlerConfig.ts

This file was deleted.

15 changes: 9 additions & 6 deletions packages/shared/src/types/config/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ import type {
ConfigChainAsyncWithContext,
ConfigChainWithContext,
} from '../../reduceConfigs';
import type { BundlerChain } from '../bundlerConfig';
import type { BundlerPluginInstance } from '../bundlerConfig';
import type { ModifyBundlerChainUtils, ModifyChainUtils } from '../hooks';
import type {
ModifyWebpackChainUtils,
ModifyWebpackConfigUtils,
} from '../plugin';
import type { Rspack, RspackConfig, RspackRule } from '../rspack';
import type {
BundlerPluginInstance,
Rspack,
RspackConfig,
RspackRule,
} from '../rspack';
import type {
AutoprefixerOptions,
CSSExtractOptions,
Expand All @@ -32,7 +35,7 @@ export type ToolsSwcConfig = ConfigChain<SwcLoaderOptions>;
export type ToolsAutoprefixerConfig = ConfigChain<AutoprefixerOptions>;

export type ToolsBundlerChainConfig = OneOrMany<
(chain: BundlerChain, utils: ModifyBundlerChainUtils) => MaybePromise<void>
(chain: RspackChain, utils: ModifyBundlerChainUtils) => MaybePromise<void>
>;

export type ToolsPostCSSLoaderConfig = ConfigChainWithContext<
Expand Down Expand Up @@ -81,7 +84,7 @@ export type ToolsWebpackChainConfig = OneOrMany<

export interface ToolsConfig {
/**
* Configure bundler config base on [webpack-chain](https://github.com/neutrinojs/webpack-chain)
* Configure bundler config base on [rspack-chain](https://github.com/rspack-contrib/rspack-chain)
*/
bundlerChain?: ToolsBundlerChainConfig;
/**
Expand Down Expand Up @@ -123,7 +126,7 @@ export interface ToolsConfig {
*/
webpack?: ToolsWebpackConfig;
/**
* Configure webpack by [webpack-chain](https://github.com/neutrinojs/webpack-chain).
* Configure webpack by [rspack-chain](https://github.com/rspack-contrib/rspack-chain).
* @requires webpack
*/
webpackChain?: ToolsWebpackChainConfig;
Expand Down
5 changes: 2 additions & 3 deletions packages/shared/src/types/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import type HtmlWebpackPlugin from 'html-webpack-plugin';
import type { ChainIdentifier } from '../chain';
import type { BundlerChain } from './bundlerConfig';
import type { HtmlBasicTag, RsbuildConfig } from './config';
import type { RsbuildTarget } from './rsbuild';
import type { Rspack, RspackConfig } from './rspack';
import type { MultiStats, Stats } from './stats';
import type { WebpackConfig } from './thirdParty';
import type { MaybePromise, NodeEnv } from './utils';
import type { MaybePromise, NodeEnv, RspackChain } from './utils';

export type OnBeforeBuildFn<B = 'rspack'> = (params: {
bundlerConfigs?: B extends 'rspack' ? RspackConfig[] : WebpackConfig[];
Expand Down Expand Up @@ -118,7 +117,7 @@ export type ModifyBundlerChainUtils = ModifyChainUtils & {
};

export type ModifyBundlerChainFn = (
chain: BundlerChain,
chain: RspackChain,
utils: ModifyBundlerChainUtils,
) => MaybePromise<void>;

Expand Down
1 change: 0 additions & 1 deletion packages/shared/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ export * from './provider';
export * from './config';
export * from './stats';
export * from './hooks';
export * from './bundlerConfig';
export * from './thirdParty';
Loading

0 comments on commit e7e90ea

Please sign in to comment.