1. const svgToMiniDataURI = require("mini-svg-data-uri");
    2. module.exports = {
    3. output: {
    4. assetModuleFilename: "images/[hash][ext]"
    5. },
    6. module: {
    7. rules: [
    8. {
    9. test: /\.(png|jpg)$/,
    10. type: "asset"
    11. },
    12. {
    13. test: /\.svg$/,
    14. type: "asset",
    15. generator: {
    16. dataUrl: content => {
    17. if (typeof content !== "string") {
    18. content = content.toString();
    19. }
    20. return svgToMiniDataURI(content);
    21. }
    22. }
    23. }
    24. ]
    25. },
    26. devtool: false,
    27. experiments: {
    28. asset: true
    29. }
    30. };

    该例子展示了module.type和module.generator的用法。可以使用generator处理导入的文件,并且不需要使用file-loader和url-loader