2025-07-16 22:29:28 +08:00
|
|
|
"use strict";
|
|
|
|
|
2025-05-01 22:36:51 +08:00
|
|
|
/** @typedef {import("../../../../").Chunk} Chunk */
|
|
|
|
|
2021-04-09 21:50:25 +08:00
|
|
|
/** @type {import("../../../../").Configuration} */
|
|
|
|
module.exports = {
|
|
|
|
output: {
|
|
|
|
publicPath: "/public/"
|
|
|
|
},
|
|
|
|
module: {
|
|
|
|
parser: {
|
|
|
|
javascript: {
|
|
|
|
url: "relative"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
rules: [
|
2021-09-03 22:17:04 +08:00
|
|
|
{
|
|
|
|
dependency: "url",
|
|
|
|
issuer: /stylesheet\.js$/,
|
|
|
|
type: "asset/resource",
|
|
|
|
generator: {
|
|
|
|
filename: "assets/[name][ext][query]"
|
|
|
|
}
|
|
|
|
},
|
2021-04-09 21:50:25 +08:00
|
|
|
{
|
2021-04-15 01:48:22 +08:00
|
|
|
oneOf: [
|
|
|
|
{
|
|
|
|
test: /other-stylesheet\.js$/,
|
|
|
|
loader: "./loader",
|
|
|
|
options: {
|
|
|
|
publicPath: "/other/"
|
|
|
|
},
|
|
|
|
type: "asset/source"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /stylesheet\.js$/,
|
|
|
|
use: "./loader",
|
|
|
|
type: "asset/source"
|
|
|
|
}
|
|
|
|
]
|
2021-04-12 16:51:53 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.jpg$/,
|
|
|
|
loader: "file-loader",
|
|
|
|
options: {
|
|
|
|
name: "assets/[name].[ext]"
|
|
|
|
}
|
2021-04-09 21:50:25 +08:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
plugins: [
|
2025-07-17 00:13:14 +08:00
|
|
|
(compiler) =>
|
|
|
|
compiler.hooks.done.tap("test case", (stats) => {
|
2021-09-03 22:17:04 +08:00
|
|
|
try {
|
|
|
|
expect(stats.compilation.getAsset("assets/file.png")).toHaveProperty(
|
|
|
|
"info",
|
|
|
|
expect.objectContaining({ sourceFilename: "file.png" })
|
|
|
|
);
|
|
|
|
expect(stats.compilation.getAsset("assets/file.jpg")).toHaveProperty(
|
|
|
|
"info",
|
|
|
|
expect.objectContaining({ sourceFilename: "file.jpg" })
|
|
|
|
);
|
2025-05-01 22:36:51 +08:00
|
|
|
const { auxiliaryFiles } =
|
|
|
|
/** @type {Chunk} */
|
|
|
|
(stats.compilation.namedChunks.get("main"));
|
2021-09-03 22:17:04 +08:00
|
|
|
expect(auxiliaryFiles).toContain("assets/file.png");
|
|
|
|
expect(auxiliaryFiles).toContain("assets/file.png?1");
|
|
|
|
expect(auxiliaryFiles).toContain("assets/file.jpg");
|
2024-07-31 15:37:05 +08:00
|
|
|
} catch (err) {
|
2021-09-03 22:17:04 +08:00
|
|
|
console.log(stats.toString({ colors: true, orphanModules: true }));
|
2024-07-31 15:37:05 +08:00
|
|
|
throw err;
|
2021-09-03 22:17:04 +08:00
|
|
|
}
|
2021-04-12 16:51:53 +08:00
|
|
|
})
|
2021-04-09 21:50:25 +08:00
|
|
|
]
|
|
|
|
};
|