Skip to content

Commit

Permalink
fix(app-tools): align resolve.modules config in rspack mode (#4762)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Oct 10, 2023
1 parent e27c843 commit c1b0d18
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
8 changes: 8 additions & 0 deletions .changeset/perfect-dolphins-begin.md
Original file line number Diff line number Diff line change
@@ -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 配置
1 change: 1 addition & 0 deletions packages/builder/builder-shared/src/types/bundlerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type RspackResolve = {
conditionNames?: string[];
alias?: Record<string, false | string | string[]>;
tsConfigPath?: string;
modules?: string[];
fallback?: Record<string, false | string>;
};

Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import path from 'path';
import { BuilderPlugin, BundlerChain } from '@modern-js/builder-shared';
import type { BuilderPluginAPI } from '../types';

Expand Down Expand Up @@ -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'));
});
},
});
Expand Down

0 comments on commit c1b0d18

Please sign in to comment.