Skip to content

Commit

Permalink
fix: preserve require.resolve / dynamic require / dynamic import (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework authored Sep 30, 2024
1 parent 076658d commit 73487a4
Show file tree
Hide file tree
Showing 19 changed files with 322 additions and 186 deletions.
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,6 @@ Here are the steps to publish (we generally use CI for releases and avoid publis

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:

| Package | Link |
| ------------ | --------------------------------------------------------------------------------------- |
| @rspack/core | https://github.com/web-infra-dev/rspack/commit/bb0219fd3eaee45d9957b4c29a176f2ac67a84ee |
| Package | Link |
| ------------ | ------------------------------------------------- |
| @rspack/core | https://github.com/web-infra-dev/rspack/pull/7939 |
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
},
"pnpm": {
"overrides": {
"@rspack/core": "npm:@rspack/core-canary@1.0.6-canary-bb0219fd-20240920080859"
"@rspack/core": "npm:@rspack/core-canary@1.0.9-canary-0cad17d5-20240929151646"
}
}
}
17 changes: 11 additions & 6 deletions packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,14 @@ export async function createConstantRsbuildConfig(): Promise<RsbuildConfig> {
}

const composeFormatConfig = (format: Format): RsbuildConfig => {
const jsParserOptions = {
importMeta: false,
requireResolve: false,
requireDynamic: false,
requireAsExpression: false,
importDynamic: false,
};

switch (format) {
case 'esm':
return {
Expand All @@ -446,13 +454,12 @@ const composeFormatConfig = (format: Format): RsbuildConfig => {
},
module: {
parser: {
javascript: {
importMeta: false,
},
javascript: jsParserOptions,
},
},
optimization: {
concatenateModules: true,
sideEffects: 'flag',
},
experiments: {
outputModule: true,
Expand All @@ -467,9 +474,7 @@ const composeFormatConfig = (format: Format): RsbuildConfig => {
rspack: {
module: {
parser: {
javascript: {
importMeta: false,
},
javascript: jsParserOptions,
},
},
output: {
Expand Down
9 changes: 9 additions & 0 deletions packages/core/tests/__snapshots__/config.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,17 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1
"module": {
"parser": {
"javascript": {
"importDynamic": false,
"importMeta": false,
"requireAsExpression": false,
"requireDynamic": false,
"requireResolve": false,
},
},
},
"optimization": {
"concatenateModules": true,
"sideEffects": "flag",
},
"output": {
"chunkFormat": "module",
Expand Down Expand Up @@ -252,7 +257,11 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1
"module": {
"parser": {
"javascript": {
"importDynamic": false,
"importMeta": false,
"requireAsExpression": false,
"requireDynamic": false,
"requireResolve": false,
},
},
},
Expand Down
118 changes: 63 additions & 55 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 73487a4

Please sign in to comment.