-
-
Notifications
You must be signed in to change notification settings - Fork 553
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: avoid import external module re-assigin in concatenation (#7839)
* fix: avoid import external module re-assigin in concatenation * test: add test
- Loading branch information
Showing
14 changed files
with
143 additions
and
13 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
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
4 changes: 4 additions & 0 deletions
4
...spack-test-tools/tests/configCases/externals/0-concatenation-tree-shaking/externals/m.mjs
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,4 @@ | ||
export const m1 = 11111; | ||
export const m2 = 22222; | ||
|
||
export const m1Add = () => m1++; |
3 changes: 3 additions & 0 deletions
3
packages/rspack-test-tools/tests/configCases/externals/0-concatenation-tree-shaking/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,3 @@ | ||
import { m1, m2, m1Add } from "./externals/m.mjs"; | ||
|
||
export { m1, m2, m1Add } |
23 changes: 23 additions & 0 deletions
23
...pack-test-tools/tests/configCases/externals/0-concatenation-tree-shaking/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,23 @@ | ||
const rspack = require("@rspack/core"); | ||
|
||
/** @type {import("@rspack/core").Configuration} */ | ||
module.exports = { | ||
externals: [/\.\/externals\/.*/], | ||
externalsType: "module", | ||
output: { | ||
module: true, | ||
chunkFormat: "module", | ||
filename: "[name].mjs", | ||
library: { | ||
type: "modern-module", | ||
} | ||
}, | ||
experiments: { | ||
outputModule: true | ||
}, | ||
plugins: [ | ||
new rspack.CopyRspackPlugin({ | ||
patterns: ["./externals/**/*"], | ||
}), | ||
] | ||
}; |
1 change: 1 addition & 0 deletions
1
...rspack-test-tools/tests/configCases/externals/0-concatenation-tree-shaking/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 @@ | ||
exports.noTests = true; |
3 changes: 3 additions & 0 deletions
3
...ges/rspack-test-tools/tests/configCases/externals/1-concatenation-tree-shaking/consume.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 { m1Add } from 'library' | ||
|
||
m1Add() |
7 changes: 7 additions & 0 deletions
7
packages/rspack-test-tools/tests/configCases/externals/1-concatenation-tree-shaking/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,7 @@ | ||
import fs from "fs"; | ||
import path from "path"; | ||
|
||
it("static import from external module should be tree shaking friendly", () => { | ||
const content = fs.readFileSync(path.resolve(__dirname, "consume.mjs"), "utf-8"); | ||
expect(content).not.toContain("22222"); | ||
}); |
38 changes: 38 additions & 0 deletions
38
...pack-test-tools/tests/configCases/externals/1-concatenation-tree-shaking/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,38 @@ | ||
const { rspack } = require("@rspack/core"); | ||
const path = require("path"); | ||
|
||
/** @type {function(any, any): import("@rspack/core").Configuration[]} */ | ||
module.exports = (env, { testPath }) => { | ||
return { | ||
entry: { | ||
consume: "./consume.js", | ||
main: "./index.js" | ||
}, | ||
resolve: { | ||
alias: { | ||
library: path.resolve(testPath, "../0-concatenation-tree-shaking/main.mjs") | ||
} | ||
}, | ||
output: { | ||
module: true, | ||
chunkFormat: "module", | ||
filename: "[name].mjs" | ||
}, | ||
experiments: { | ||
outputModule: true | ||
}, | ||
optimization: { | ||
minimize: true, | ||
concatenateModules: true, | ||
}, | ||
plugins: [ | ||
new rspack.SwcJsMinimizerRspackPlugin({ | ||
minimizerOptions: { | ||
minify: false, | ||
mangle: false | ||
} | ||
}) | ||
] | ||
}; | ||
} | ||
|
6 changes: 6 additions & 0 deletions
6
...rspack-test-tools/tests/configCases/externals/1-concatenation-tree-shaking/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 ["main.mjs"]; | ||
} | ||
}; |
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
0a89e43
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
0a89e43
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