Skip to content
Merged
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
8 changes: 8 additions & 0 deletions .changeset/thin-results-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@modern-js/plugin-router-v7': patch
'@modern-js/main-doc': patch
'@modern-js/uni-builder': patch
---

fix: keep the default behavior of scope for compiling JS when use webpack after upgrade to Rsbuild 1.4
fix: 升级到 Rsbuild 1.4 后,如果使用 Webpack 构建,保持默认的 JS 编译范围
3 changes: 3 additions & 0 deletions packages/cli/uni-builder/src/webpack/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type {
UniBuilderConfig,
} from '../types';
import { pluginBabel } from './plugins/babel';
import { pluginInclude } from './plugins/include';
import { pluginModuleScopes } from './plugins/moduleScopes';
import { pluginReact } from './plugins/react';

Expand Down Expand Up @@ -158,6 +159,8 @@ export async function parseConfig(
pluginModuleScopes(uniBuilderConfig.source?.moduleScopes),
);

rsbuildPlugins.push(pluginInclude());

return {
rsbuildConfig,
rsbuildPlugins,
Expand Down
28 changes: 28 additions & 0 deletions packages/cli/uni-builder/src/webpack/plugins/include.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { RsbuildPlugin } from '@rsbuild/core';

// Preserve the default behavior of compilation scope to the current directory when using webpack.
// TODO: Remove this plugin in next major version.
export const pluginInclude = (): RsbuildPlugin => ({
name: 'uni-builder:babel-include',

setup(api) {
api.modifyWebpackChain((chain, { CHAIN_ID }) => {
const includes = chain.module.rule(CHAIN_ID.RULE.JS).include.values();
includes.forEach(include => {
if (
typeof include === 'object' &&
!Array.isArray(include) &&
!(include instanceof RegExp) &&
include.not &&
include.not.toString() === /[\\/]node_modules[\\/]/.toString()
) {
include.and = [
api.context.rootPath || process.cwd(),
{ not: include.not },
];
delete include.not;
}
});
});
},
});
98 changes: 84 additions & 14 deletions packages/cli/uni-builder/tests/__snapshots__/babel.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,12 @@ exports[`plugin-babel > should add core-js-entry when output.polyfill is entry 1
},
"include": [
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
"and": [
"<ROOT>",
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
],
},
/\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/,
],
Expand Down Expand Up @@ -948,7 +953,12 @@ exports[`plugin-babel > should adjust browserslist when target is node 1`] = `
},
"include": [
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
"and": [
"<ROOT>",
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
],
},
/\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/,
],
Expand Down Expand Up @@ -1078,7 +1088,12 @@ exports[`plugin-babel > should apply exclude condition when using source.exclude
],
"include": [
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
"and": [
"<ROOT>",
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
],
},
/\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/,
],
Expand Down Expand Up @@ -1226,7 +1241,12 @@ exports[`plugin-babel > should merge environment and shared babel config 1`] = `
},
"include": [
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
"and": [
"<ROOT>",
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
],
},
/\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/,
],
Expand Down Expand Up @@ -1390,7 +1410,12 @@ exports[`plugin-babel > should merge environment and shared babel config 2`] = `
},
"include": [
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
"and": [
"<ROOT>",
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
],
},
/\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/,
],
Expand Down Expand Up @@ -1546,7 +1571,12 @@ exports[`plugin-babel > should not add core-js-entry when output.polyfill is usa
},
"include": [
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
"and": [
"<ROOT>",
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
],
},
/\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/,
],
Expand Down Expand Up @@ -1688,7 +1718,12 @@ exports[`plugin-babel > should not have any pluginImport in Babel 1`] = `
},
"include": [
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
"and": [
"<ROOT>",
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
],
},
/\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/,
],
Expand Down Expand Up @@ -1908,7 +1943,12 @@ exports[`plugin-babel > should not set default pluginImport for Babel 1`] = `
},
"include": [
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
"and": [
"<ROOT>",
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
],
},
/\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/,
],
Expand Down Expand Up @@ -2172,7 +2212,12 @@ exports[`plugin-babel > should override targets of babel-preset-env when using o
},
"include": [
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
"and": [
"<ROOT>",
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
],
},
/\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/,
],
Expand Down Expand Up @@ -2318,7 +2363,12 @@ exports[`plugin-babel > should set babel-loader 1`] = `
},
"include": [
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
"and": [
"<ROOT>",
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
],
},
/\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/,
],
Expand Down Expand Up @@ -2466,7 +2516,12 @@ exports[`plugin-babel > should set babel-loader separate by environment 1`] = `
},
"include": [
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
"and": [
"<ROOT>",
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
],
},
/\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/,
],
Expand Down Expand Up @@ -2622,7 +2677,12 @@ exports[`plugin-babel > should set babel-loader separate by environment 2`] = `
},
"include": [
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
"and": [
"<ROOT>",
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
],
},
/\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/,
],
Expand Down Expand Up @@ -2773,7 +2833,12 @@ exports[`plugin-babel > should set include/exclude 1`] = `
],
"include": [
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
"and": [
"<ROOT>",
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
],
},
/\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/,
"src/**/*.ts",
Expand Down Expand Up @@ -2916,7 +2981,12 @@ exports[`plugin-babel > should set proper pluginImport option in Babel 1`] = `
},
"include": [
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
"and": [
"<ROOT>",
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
],
},
/\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/,
],
Expand Down
14 changes: 12 additions & 2 deletions packages/cli/uni-builder/tests/__snapshots__/default.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4852,7 +4852,12 @@ exports[`uni-builder webpack > should generator webpack config correctly 1`] = `
},
"include": [
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
"and": [
"<ROOT>",
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
],
},
/\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/,
/\\[\\\\\\\\/\\]@rsbuild\\[\\\\\\\\/\\]core\\[\\\\\\\\/\\]dist\\[\\\\\\\\/\\]/,
Expand Down Expand Up @@ -6418,7 +6423,12 @@ exports[`uni-builder webpack > should generator webpack config correctly when pr
},
"include": [
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
"and": [
"<ROOT>",
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
],
},
/\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ exports[`plugins/react > should work with babel-loader 1`] = `
},
"include": [
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
"and": [
"<ROOT>",
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
],
},
/\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ exports[`plugins/styled-components > should enable ssr when target contain node
},
"include": [
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
"and": [
"<ROOT>",
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
],
},
/\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/,
],
Expand Down Expand Up @@ -162,7 +167,12 @@ exports[`plugins/styled-components > should enable ssr when target contain node
},
"include": [
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
"and": [
"<ROOT>",
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
],
},
/\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/,
],
Expand Down Expand Up @@ -289,7 +299,12 @@ exports[`plugins/styled-components > should works in webpack babel mode 1`] = `
},
"include": [
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
"and": [
"<ROOT>",
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
],
},
/\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/,
],
Expand Down Expand Up @@ -437,7 +452,12 @@ exports[`plugins/styled-components > should works in webpack swc mode 1`] = `
},
"include": [
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
"and": [
"<ROOT>",
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
],
},
/\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/,
],
Expand Down
Loading