Skip to content

Commit 73487a4

Browse files
authored
fix: preserve require.resolve / dynamic require / dynamic import (#249)
1 parent 076658d commit 73487a4

File tree

19 files changed

+322
-186
lines changed

19 files changed

+322
-186
lines changed

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,6 @@ Here are the steps to publish (we generally use CI for releases and avoid publis
138138

139139
The project is still in its early stages and under active development, so it possible dependents on Rsbuild or Rspack canary versions to test the latest features. The current versions are:
140140

141-
| Package | Link |
142-
| ------------ | --------------------------------------------------------------------------------------- |
143-
| @rspack/core | https://github.com/web-infra-dev/rspack/commit/bb0219fd3eaee45d9957b4c29a176f2ac67a84ee |
141+
| Package | Link |
142+
| ------------ | ------------------------------------------------- |
143+
| @rspack/core | https://github.com/web-infra-dev/rspack/pull/7939 |

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
},
6464
"pnpm": {
6565
"overrides": {
66-
"@rspack/core": "npm:@rspack/[email protected].6-canary-bb0219fd-20240920080859"
66+
"@rspack/core": "npm:@rspack/[email protected].9-canary-0cad17d5-20240929151646"
6767
}
6868
}
6969
}

packages/core/src/config.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,14 @@ export async function createConstantRsbuildConfig(): Promise<RsbuildConfig> {
432432
}
433433

434434
const composeFormatConfig = (format: Format): RsbuildConfig => {
435+
const jsParserOptions = {
436+
importMeta: false,
437+
requireResolve: false,
438+
requireDynamic: false,
439+
requireAsExpression: false,
440+
importDynamic: false,
441+
};
442+
435443
switch (format) {
436444
case 'esm':
437445
return {
@@ -446,13 +454,12 @@ const composeFormatConfig = (format: Format): RsbuildConfig => {
446454
},
447455
module: {
448456
parser: {
449-
javascript: {
450-
importMeta: false,
451-
},
457+
javascript: jsParserOptions,
452458
},
453459
},
454460
optimization: {
455461
concatenateModules: true,
462+
sideEffects: 'flag',
456463
},
457464
experiments: {
458465
outputModule: true,
@@ -467,9 +474,7 @@ const composeFormatConfig = (format: Format): RsbuildConfig => {
467474
rspack: {
468475
module: {
469476
parser: {
470-
javascript: {
471-
importMeta: false,
472-
},
477+
javascript: jsParserOptions,
473478
},
474479
},
475480
output: {

packages/core/tests/__snapshots__/config.test.ts.snap

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,17 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1
102102
"module": {
103103
"parser": {
104104
"javascript": {
105+
"importDynamic": false,
105106
"importMeta": false,
107+
"requireAsExpression": false,
108+
"requireDynamic": false,
109+
"requireResolve": false,
106110
},
107111
},
108112
},
109113
"optimization": {
110114
"concatenateModules": true,
115+
"sideEffects": "flag",
111116
},
112117
"output": {
113118
"chunkFormat": "module",
@@ -252,7 +257,11 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1
252257
"module": {
253258
"parser": {
254259
"javascript": {
260+
"importDynamic": false,
255261
"importMeta": false,
262+
"requireAsExpression": false,
263+
"requireDynamic": false,
264+
"requireResolve": false,
256265
},
257266
},
258267
},

pnpm-lock.yaml

Lines changed: 63 additions & 55 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)