Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
364 changes: 189 additions & 175 deletions crates/rspack_plugin_javascript/src/plugin/module_concatenation_plugin.rs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { getValue as getRootAValue } from "./root-a";
import { stable } from "./root-shared";

it("should keep runtime-specific concatenation results isolated", () => {
expect(getRootAValue()).toBe(42);
expect(stable).toBe(1);

const rootAGroup = __STATS__.modules.find(module =>
module.modules?.some(nested => nested.name.endsWith("root-a.js"))
);
expect(rootAGroup).toBeDefined();

const shared = __STATS__.modules.find(module => module.name.endsWith("root-shared.js"));
expect(shared).toBeDefined();
const expectedBailout = globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK
? "runtime-dependent referenced"
: "not in the same chunk(s)";
expect(shared.optimizationBailout).toEqual(
expect.arrayContaining([expect.stringContaining(expectedBailout)])
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { getValue } from "./root-shared";

it("should preserve the runtime-dependent export", () => {
expect(getValue()).toBe(42);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export let value = 42;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { value } from "./leaf";

export const getValue = () => value;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { value } from "./leaf";

export const stable = 1;
export const getValue = () => value;
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/** @type {import("@rspack/core").Configuration} */
module.exports = {
mode: 'production',
entry: {
a: './a.js',
b: './b.js',
},
output: {
filename: '[name].js',
},
module: {
rules: [
{
test: /\.js$/,
sideEffects: false,
},
],
},
optimization: {
concatenateModules: true,
innerGraph: true,
minimize: false,
sideEffects: true,
splitChunks: {
chunks: 'all',
minSize: 0,
cacheGroups: {
shared: {
enforce: true,
name: 'shared',
test: /root-shared/,
},
},
},
usedExports: true,
},
stats: {
modules: true,
nestedModules: true,
optimizationBailout: true,
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
findBundle() {
return ["shared.js", "a.js", "b.js"];
},
};
Loading