webpack/examples/asset-svg-data-uri/webpack.config.js

31 lines
469 B
JavaScript
Raw Permalink Normal View History

"use strict";
const svgToMiniDataURI = require("mini-svg-data-uri");
2019-11-16 00:27:36 +08:00
module.exports = {
output: {
assetModuleFilename: "images/[hash][ext]"
},
module: {
rules: [
{
2019-11-18 22:04:49 +08:00
test: /\.(png|jpg)$/,
type: "asset"
},
{
test: /\.svg$/,
2019-11-16 00:27:36 +08:00
type: "asset",
generator: {
dataUrl: content => {
2019-11-18 00:49:48 +08:00
if (typeof content !== "string") {
content = content.toString();
}
return svgToMiniDataURI(content);
2019-11-16 00:27:36 +08:00
}
}
}
]
}
};