-
-
Notifications
You must be signed in to change notification settings - Fork 573
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(externals): support 'commonjs-import' type (#8414)
- Loading branch information
Showing
10 changed files
with
198 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/rspack-test-tools/tests/configCases/externals/commonjs-import/case.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import e1 from 'external1' | ||
const e2 = import('external2') | ||
|
11 changes: 11 additions & 0 deletions
11
packages/rspack-test-tools/tests/configCases/externals/commonjs-import/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const readCase = (name)=> fs.readFileSync(path.resolve(__dirname, `${name}.js`), "utf-8"); | ||
const caseContent = readCase("case"); | ||
|
||
it("dynamic import should be preserved, others should be in commonjs external", function () { | ||
expect(caseContent).toContain(`import("external2-alias")`) | ||
expect(caseContent).toContain(`require("external1-alias")`) | ||
expect(caseContent).not.toContain(`require("external2-alias")`) | ||
expect(caseContent).toContain(`const e2 = Promise.resolve(/* import() */).then(__webpack_require__.bind(__webpack_require__, `) | ||
}); |
19 changes: 19 additions & 0 deletions
19
packages/rspack-test-tools/tests/configCases/externals/commonjs-import/rspack.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** @type {import("@rspack/core").Configuration} */ | ||
module.exports = [ | ||
{ | ||
target: "node", | ||
entry: { | ||
"index": "./index.js", | ||
"case": "./case.js", | ||
}, | ||
externalsType: "commonjs-import", | ||
output: { | ||
module: false, | ||
filename: "[name].js", | ||
}, | ||
externals: { | ||
external1: "external1-alias", | ||
external2: "external2-alias", | ||
}, | ||
}, | ||
]; |
6 changes: 6 additions & 0 deletions
6
packages/rspack-test-tools/tests/configCases/externals/commonjs-import/test.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** @type {import("../../../../dist").TConfigCaseConfig} */ | ||
module.exports = { | ||
findBundle: (i, options) => { | ||
return ["index.js"]; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
92ce991
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 Benchmark detail: Open
92ce991
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 Ran ecosystem CI: Open