Skip to content

Commit

Permalink
feat(core): don't inject bundlerInfo in library mode (#7567)
Browse files Browse the repository at this point in the history
  • Loading branch information
hardfist authored Aug 15, 2024
1 parent a5e3212 commit ed5b33b
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
it('should not inject bundlerInfo when library is truthy', () => {
const content = require('fs').readFileSync(
require('path').resolve(__dirname, "bundle0.js"),
"utf-8"
);
expect(content).not.toContain('__webpack_require__' + '.rv')
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import("@rspack/core").Configuration} */
module.exports = {
output: {
library: {
type: 'modern-module'
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
it('should inject bundlerInfo when library is falsy', () => {
const content = require('fs').readFileSync(
require('path').resolve(__dirname, "bundle0.js"),
"utf-8"
);
expect(content).toContain('__webpack_require__.rv')
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @type {import("@rspack/core").Configuration} */
module.exports = {
output: {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ module.exports = {
- Expected
+ Received
@@ ... @@
- "force": true,
+ "force": false,
@@ ... @@
- "chunkLoadingGlobal": "webpackChunk_rspack_test_tools",
+ "chunkLoadingGlobal": "webpackChunkmyLib_awesome",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ module.exports = {
- Expected
+ Received
@@ ... @@
- "force": true,
+ "force": false,
@@ ... @@
- "chunkLoadingGlobal": "webpackChunk_rspack_test_tools",
+ "chunkLoadingGlobal": "webpackChunkmyLib_lib",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ module.exports = {
- Expected
+ Received
@@ ... @@
- "force": true,
+ "force": false,
@@ ... @@
- "chunkLoadingGlobal": "webpackChunk_rspack_test_tools",
+ "chunkLoadingGlobal": "webpackChunk_name_my_name_Lib_name_",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ module.exports = {
- Expected
+ Received
@@ ... @@
- "force": true,
+ "force": false,
@@ ... @@
- "chunkLoadingGlobal": "webpackChunk_rspack_test_tools",
+ "chunkLoadingGlobal": "webpackChunkmyLib",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ module.exports = {
- Expected
+ Received
@@ ... @@
- "force": true,
+ "force": false,
@@ ... @@
- "chunkLoadingGlobal": "webpackChunk_rspack_test_tools",
+ "chunkLoadingGlobal": "webpackChunkmyLib",
Expand Down
26 changes: 20 additions & 6 deletions packages/rspack/src/config/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import type {
Optimization,
Performance,
ResolveOptions,
RspackFutureOptions,
RuleSetRules,
SnapshotOptions
} from "./zod";
Expand Down Expand Up @@ -110,6 +111,11 @@ export const applyRspackOptionsDefaults = (
entry: options.entry,
futureDefaults: options.experiments.futureDefaults!
});
// bundlerInfo is affected by outputDefaults so must be executed after outputDefaults
applybundlerInfoDefaults(
options.experiments.rspackFuture,
options.output.library
);

applyExternalsPresetsDefaults(options.externalsPresets, {
targetProperties
Expand Down Expand Up @@ -197,16 +203,24 @@ const applyExperimentsDefaults = (experiments: ExperimentsNormalized) => {

// IGNORE(experiments.rspackFuture): Rspack specific configuration
D(experiments, "rspackFuture", {});
if (typeof experiments.rspackFuture === "object") {
D(experiments.rspackFuture, "bundlerInfo", {});
if (typeof experiments.rspackFuture.bundlerInfo === "object") {
// rspackFuture.bundlerInfo default value is applied after applyDefaults
};

const applybundlerInfoDefaults = (
rspackFuture?: RspackFutureOptions,
library?: Library
) => {
if (typeof rspackFuture === "object") {
D(rspackFuture, "bundlerInfo", {});
if (typeof rspackFuture.bundlerInfo === "object") {
D(
experiments.rspackFuture.bundlerInfo,
rspackFuture.bundlerInfo,
"version",
require("../../package.json").version
);
D(experiments.rspackFuture.bundlerInfo, "bundler", "rspack");
D(experiments.rspackFuture.bundlerInfo, "force", true);
D(rspackFuture.bundlerInfo, "bundler", "rspack");
// don't inject for library mode
D(rspackFuture.bundlerInfo, "force", !library);
}
}
};
Expand Down

2 comments on commit ed5b33b

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ran ecosystem CI: Open

suite result
modernjs ✅ success
_selftest ✅ success
nx ❌ failure
rspress ✅ success
rsbuild ✅ success
examples ✅ success

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Benchmark detail: Open

Name Base (2024-08-15 5271a8b) Current Change
10000_development-mode + exec 2.31 s ± 16 ms 2.37 s ± 22 ms +2.48 %
10000_development-mode_hmr + exec 697 ms ± 6.7 ms 725 ms ± 7.2 ms +4.01 %
10000_production-mode + exec 2.85 s ± 37 ms 3.04 s ± 24 ms +6.46 %
arco-pro_development-mode + exec 1.88 s ± 77 ms 1.9 s ± 82 ms +1.20 %
arco-pro_development-mode_hmr + exec 433 ms ± 2.7 ms 438 ms ± 2 ms +1.33 %
arco-pro_production-mode + exec 3.43 s ± 72 ms 3.54 s ± 76 ms +3.36 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.49 s ± 75 ms 3.57 s ± 67 ms +2.25 %
threejs_development-mode_10x + exec 1.68 s ± 15 ms 1.73 s ± 14 ms +2.91 %
threejs_development-mode_10x_hmr + exec 797 ms ± 1.8 ms 827 ms ± 8.5 ms +3.75 %
threejs_production-mode_10x + exec 5.48 s ± 28 ms 5.57 s ± 25 ms +1.60 %

Threshold exceeded: ["10000_production-mode + exec"]

Please sign in to comment.