webpack/test/configCases/asset-modules/query-and-custom-encoder/webpack.config.js

38 lines
955 B
JavaScript
Raw Normal View History

const svgToMiniDataURI = require("mini-svg-data-uri");
const mimeTypes = require("mime-types");
2025-05-01 22:36:51 +08:00
/** @typedef {import("../../../../").GeneratorOptionsByModuleTypeKnown} GeneratorOptionsByModuleTypeKnown */
/** @type {import("../../../../").Configuration} */
module.exports = {
mode: "development",
module: {
rules: [
{
test: /\.(png|svg|jpg)$/,
type: "asset/inline",
2025-05-01 22:36:51 +08:00
/** @type {GeneratorOptionsByModuleTypeKnown["asset/inline"]} */
generator: {
dataUrl: (source, { filename, module }) => {
if (filename.endsWith("?foo=bar")) {
if (typeof source !== "string") {
source = source.toString();
}
return svgToMiniDataURI(source);
}
2025-05-01 22:36:51 +08:00
const mimeType = mimeTypes.lookup(
/** @type {string} */
(module.nameForCondition())
);
const encodedContent = source.toString("base64");
return `data:${mimeType};base64,${encodedContent}`;
}
}
}
]
}
};