From c1b0d18057b2b5a89d70ffa3967830a16e9090fe Mon Sep 17 00:00:00 2001 From: neverland Date: Tue, 10 Oct 2023 10:19:38 +0800 Subject: [PATCH] fix(app-tools): align resolve.modules config in rspack mode (#4762) --- .changeset/perfect-dolphins-begin.md | 8 ++++++++ .../builder/builder-shared/src/types/bundlerConfig.ts | 1 + .../src/builder/builder-webpack/adapterModern.ts | 6 ------ .../src/builder/shared/builderPlugins/adapterBasic.ts | 7 +++++++ 4 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 .changeset/perfect-dolphins-begin.md diff --git a/.changeset/perfect-dolphins-begin.md b/.changeset/perfect-dolphins-begin.md new file mode 100644 index 000000000000..78e1927ddf4d --- /dev/null +++ b/.changeset/perfect-dolphins-begin.md @@ -0,0 +1,8 @@ +--- +'@modern-js/builder-shared': patch +'@modern-js/app-tools': patch +--- + +fix(app-tools): align resolve.modules config in rspack mode + +fix(app-tools): 对齐 rspack 模式下的 resolve.modules 配置 diff --git a/packages/builder/builder-shared/src/types/bundlerConfig.ts b/packages/builder/builder-shared/src/types/bundlerConfig.ts index 2cfa4c70e56e..aad5d9d2b026 100644 --- a/packages/builder/builder-shared/src/types/bundlerConfig.ts +++ b/packages/builder/builder-shared/src/types/bundlerConfig.ts @@ -38,6 +38,7 @@ type RspackResolve = { conditionNames?: string[]; alias?: Record; tsConfigPath?: string; + modules?: string[]; fallback?: Record; }; diff --git a/packages/solutions/app-tools/src/builder/builder-webpack/adapterModern.ts b/packages/solutions/app-tools/src/builder/builder-webpack/adapterModern.ts index b10848336ab1..88c50d058e1f 100644 --- a/packages/solutions/app-tools/src/builder/builder-webpack/adapterModern.ts +++ b/packages/solutions/app-tools/src/builder/builder-webpack/adapterModern.ts @@ -1,4 +1,3 @@ -import { join } from 'path'; import { BuilderPlugin } from '@modern-js/builder-shared'; import type { BuilderPluginAPI } from '@modern-js/builder-webpack-provider'; import { BuilderOptions } from '../shared'; @@ -16,11 +15,6 @@ export const builderPluginAdapterModern = ( const { normalizedConfig: modernConfig, appContext } = options; api.modifyWebpackChain((chain, { CHAIN_ID }) => { - // compat modern-js v1 - chain.resolve.modules - .add('node_modules') - .add(join(api.context.rootPath, 'node_modules')); - // apply copy plugin if (chain.plugins.has(CHAIN_ID.PLUGIN.COPY)) { const defaultCopyPattern = createPublicPattern( diff --git a/packages/solutions/app-tools/src/builder/shared/builderPlugins/adapterBasic.ts b/packages/solutions/app-tools/src/builder/shared/builderPlugins/adapterBasic.ts index fe90cde43468..cf6ce7d58dc5 100644 --- a/packages/solutions/app-tools/src/builder/shared/builderPlugins/adapterBasic.ts +++ b/packages/solutions/app-tools/src/builder/shared/builderPlugins/adapterBasic.ts @@ -1,3 +1,4 @@ +import path from 'path'; import { BuilderPlugin, BundlerChain } from '@modern-js/builder-shared'; import type { BuilderPluginAPI } from '../types'; @@ -34,6 +35,12 @@ export const builderPluginAdapterBasic = .use('server-module-loader') .loader(require.resolve('../loaders/serverModuleLoader')); } + + // compat modern-js v1 + // this helps symlinked packages to resolve packages correctly, such as `react/jsx-runtime`. + chain.resolve.modules + .add('node_modules') + .add(path.join(api.context.rootPath, 'node_modules')); }); }, });