Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
hyf0 committed May 5, 2023
1 parent e2e9320 commit 93086f9
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 5 deletions.
1 change: 1 addition & 0 deletions crates/node_binding/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,7 @@ export interface RawSnapshotStrategy {
}

export interface RawSplitChunksOptions {
name?: string
cacheGroups?: Record<string, RawCacheGroupOptions>
/** What kind of chunks should be selected. */
chunks?: string
Expand Down
1 change: 1 addition & 0 deletions packages/rspack/src/config/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ function getRawSplitChunksOptions(
sc: OptimizationSplitChunksOptions
): RawOptions["optimization"]["splitChunks"] {
return {
name: sc.name,
cacheGroups: sc.cacheGroups
? Object.fromEntries(
Object.entries(sc.cacheGroups).map(([key, group]) => {
Expand Down
8 changes: 8 additions & 0 deletions packages/rspack/src/config/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,14 @@ module.exports = {
type: "object",
additionalProperties: false,
properties: {
name: {
description: "The name or name for chunks.",
anyOf: [
{
type: "string"
}
]
},
cacheGroups: {
description:
"Assign modules to a cache group (modules from different cache groups are tried to keep in separate chunks, default categories: 'default', 'defaultVendors').",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ it("should run", function () {
expect(a).toBe("a");
});

it("should be main", function () {
expect(require.main).toBe(module);
});
// TODO: Rspack doesn't support `require.main`
// it("should be main", function () {
// expect(require.main).toBe(module);
// });
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,3 @@ it("should extract css to single chunk", () => {
expect(fs.existsSync(path.resolve(__dirname, "./main.css"))).toBe(false);
expect(fs.existsSync(path.resolve(__dirname, "./styles.css"))).toBe(true);
});

console.log(__dirname);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default "foo-2.js";
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import "./foo-2";
export default "foo.js";
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
() => import("./foo");

import fs from "fs";
import path from "path";

export default "index.js";

it("split-chunks-dot-name", () => {
expect(fs.existsSync(path.resolve(__dirname, "./overall-foo.js"))).toBe(true);
expect(fs.existsSync(path.resolve(__dirname, "./main.js"))).toBe(true);
expect(fs.existsSync(path.resolve(__dirname, "./foo_js.js"))).toBe(false);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/** @type {import("../../../../").Configuration} */
module.exports = {
target: "node",
entry: "./index.js",
output: {
filename: "[name].js"
},
experiments: {
newSplitChunks: true
},
optimization: {
splitChunks: {
minSize: 1,
name: "overall-foo",
cacheGroups: {
foo: {
test: /foo\.js/,
priority: 0
},
foo2: {
test: /foo-2\.js/,
priority: 0
}
}
}
}
};

0 comments on commit 93086f9

Please sign in to comment.