-
-
Notifications
You must be signed in to change notification settings - Fork 602
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: allow passing function type to assets generator.filename (#…
- Loading branch information
Showing
6 changed files
with
114 additions
and
65 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
11 changes: 11 additions & 0 deletions
11
packages/rspack-test-tools/tests/configCases/asset/filename/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 @@ | ||
import png from "../_images/file.png"; | ||
import png1 from "../_images/file.png?custom1"; | ||
import png2 from "../_images/file.png?custom2"; | ||
import jpeg2 from "../_images/file.jpg?custom2"; | ||
|
||
it("should change filenames", () => { | ||
expect(png).toEqual("images/failure.png"); | ||
expect(png1).toEqual("custom-images/success1.png"); | ||
expect(png2).toEqual("custom-images/success2.png"); | ||
expect(jpeg2).toEqual("images/failure2.jpg"); | ||
}); |
38 changes: 38 additions & 0 deletions
38
packages/rspack-test-tools/tests/configCases/asset/filename/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 @@ | ||
/** | ||
* this test case is in addition to webpack-test/configCases/asset-modules/assetModuleFilename | ||
*/ | ||
/** @type {import("@rspack/core").Configuration} */ | ||
module.exports = { | ||
mode: "development", | ||
output: { | ||
assetModuleFilename: "images/failure[ext]" | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.(png|jpg)$/, | ||
type: "asset/resource", | ||
rules: [ | ||
{ | ||
resourceQuery: "?custom1", | ||
generator: { | ||
filename: "custom-images/success1[ext]" | ||
} | ||
}, | ||
|
||
{ | ||
resourceQuery: "?custom2", | ||
generator: { | ||
filename: ({ filename }) => { | ||
if (filename.endsWith(".png?custom2")) { | ||
return "custom-images/success2[ext]"; | ||
} | ||
return "images/failure2[ext]"; | ||
} | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} | ||
}; |
Oops, something went wrong.
03b3641
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
03b3641
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